Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 22

Thread: Property bug in Spring Data MongoDB Support 1.0.0.M1

  1. #11

    Default

    If i remove my id property and add a custim field for my application(UUID) i get an Exception when i use the Repositories. IllegalArgumentException: property _id or id not found.

  2. #12
    Join Date
    Apr 2006
    Location
    Dresden, Germany
    Posts
    483

    Default

    Hi Matthias, could you please open a bug for that inside our JIRA and give some more context (stack trace, entity fields, query method name)?

    Thanks,
    Ollie

  3. #13

    Default

    Well, i don't have an account for JIRA and i don't know if it overlaps with the existing Ticket

    https://jira.springsource.org/browse/DATADOC-44

    My original problem is described in this topic:

    http://forum.springsource.org/showthread.php?t=106587

    Maybe i misunderstood how to handle Ids (PKs in RDMBM) with spring-data / mongodb

    As a workaround i tried to remove the field

    Code:
    ObjectId id;
    and replaced it with a field called

    String uuid;

    (created by java.util.UUID).

    so that there is no conflict between my id property and the one created by MongoDB.

    If i unsertood correctly, the field _id is for MongoDB only (?).

    So i have to add a logical id for my Entity which i did with the uuid property.

    Thats what i found out here:

    http://krams915.blogspot.com/2011/02...-tutorial.html

    I didn't try the MongoTemplate but i tried the Repositories:

    Code:
    @Repository
    public interface IMyResourceRepository extends MongoRepository<MyResource, String> {
    
        MyResource findByUuid(String uuid);
    
        // ...
    
    }
    Exception:

    Code:
    12:57:20,053 ERROR TestContextManager:324 - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@2929e5e9] to prepare test instance [com....@7db5391b]
    java.lang.IllegalStateException: Failed to load ApplicationContext
    	at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:308)
    	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
    	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
    	at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:220)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:301)
    	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:303)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
    	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
    	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
    	at org.junit.runners.Suite.runChild(Suite.java:128)
    	at org.junit.runners.Suite.runChild(Suite.java:24)
    	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
    	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myResourceService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private IMyResourceRepository com.....MyResourceService.resourceRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'iMyResourceRepository': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: Given domain class com.....domain.MyResource does not contain an id property!
    	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
    	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:84)
    	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:1)
    	at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:280)
    	at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:304)
    	... 32 more

  4. #14
    Join Date
    Apr 2006
    Location
    Dresden, Germany
    Posts
    483

    Default

    Hi, there's a few things to consider here. The repository support is based on the MongoTemplate which in turn uses SimpleMongoConverter by default. This converter insists on having a property name of "id" or "_id" of type ObjectId, String or BigInteger. If you want to use a different name for the id you can use an @Id annotation plus the <mongo:mapping-converter /> namespace element (which hides a MongoMappingConverter plus a MongoMappingContext). These advanced mapping features are available in the snapshots only for now and will be included into the upcoming M2 release.

    Cheers,
    Ollie

  5. #15

    Default

    The name id is fine for me. My original problem was that the delete(Entity) method of my repository doesn't work. I thought it might be because of this id issue.

    But it looks like it's a bug then

  6. #16
    Join Date
    Apr 2006
    Location
    Dresden, Germany
    Posts
    483

    Default

    What exactly does "doesn't work" mean?

  7. #17

    Default

    As you can see in this Thread (including a JUnit TestCase etc.)

    http://forum.springsource.org/showthread.php?t=106587

    the data is simply not deleted.

    Im using MongoDB 1.8 on Ubuntu with spring-data-mongo M1

    No Exceptions are thrown and no error is logged

  8. #18

    Default

    The implementation you suggest is the expected one: "It will transliterate the empId property to _id"
    Oruganti Shanker

  9. #19
    Join Date
    Aug 2004
    Location
    New York, NY
    Posts
    74

    Default

    Hi,

    Just to provide a bit more context, the M1 release contained the 'SimpleMongoConverter' and relies on naming conventions to determine what would be used as the ID field. To keep that converter 'simple' there isn't any use of mapping metadata.

    The M2 release now contains a MappingMongoConverter and is intended to provide support for all "not simple" mapping functionality. The docs for that are available here.

    Thanks for posting your original article, I posted a reference to it on the Spring Data Mongo home page, and look forward to an updated version.

    Cheers,
    Mark

  10. #20
    Join Date
    Dec 2010
    Posts
    315

    Default

    Quote Originally Posted by Mark Pollack View Post
    Hi,

    Just to provide a bit more context, the M1 release contained the 'SimpleMongoConverter' and relies on naming conventions to determine what would be used as the ID field. To keep that converter 'simple' there isn't any use of mapping metadata.

    The M2 release now contains a MappingMongoConverter and is intended to provide support for all "not simple" mapping functionality. The docs for that are available here.

    Thanks for posting your original article, I posted a reference to it on the Spring Data Mongo home page, and look forward to an updated version.

    Cheers,
    Mark
    Mark, thanks for the response. I was really planning to update my guide. I've just finished uploading it now. See it here:

    Spring Data - MongoDB (Revision for 1.0.0.M2)
    http://krams915.blogspot.com/2011/04...for-100m2.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •