I am using spring-data with MongoDB and i have trouble to delete data.
When i call delete(domainObject) it simply won't delete my data. But deleteAll() works.
I have written a simple TestCase that shows my problem.
The Repository:
This is my simple DomainObject (shortened):Code:import org.bson.types.ObjectId; import org.springframework.data.document.mongodb.repository.MongoRepository; import org.springframework.stereotype.Repository; @Repository public interface IMyResourceRepository extends MongoRepository<MyResource, ObjectId> { }
The TestCaseCode:import org.bson.types.ObjectId; public class MyResource implements Serializable { private static final long serialVersionUID = 1L; private ObjectId id; private String mimeType; private String name; // ... }
Code:@Test public void testInsertAndDelete() { MyResource resource = createResource("test.jpg", "image/jpg", "TEST"); // insert MyResource saved = resourceRepository.save(resource); assertNotNull(saved); // check if insert succeeded MyResource found = resourceRepository.findById(saved.getId()); assertNotNull(found); // check if it is the same assertEquals(saved, found); assertEquals(saved.getId(), found.getId()); // delete resourceRepository.delete(found); // check if it isn't available anymore MyResource foundAfter = resourceRepository.findById(saved.getId()); assertNull(foundAfter); // -> fails!!!!!!! resourceRepository.deleteAll(); // -> works! }
What am i doing wrong, or is this a bug?Code:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:sec="http://www.springframework.org/schema/security" xmlns:cxf="http://cxf.apache.org/core" xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:mongo="http://www.springframework.org/schema/data/mongo" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd"> <context:annotation-config /> <context:component-scan base-package="com....." /> <mongo:mongo id="mongo" host="localhost" port="27017"> <mongo:options connectionsPerHost="10" threadsAllowedToBlockForConnectionMultiplier="5" maxWaitTime="12000" /> </mongo:mongo> <mongo:repositories base-package="com...." mongo-template-ref="mongoTemplate" /> <bean id="mongoTemplate" class="org.springframework.data.document.mongodb.MongoTemplate"> <constructor-arg name="mongo" ref="mongo" /> <constructor-arg name="databaseName" value="wcmpp" /> <constructor-arg name="defaultCollectionName" value="..." /> </bean> <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" /> </beans>
Thanks for your help!


Reply With Quote
