Results 1 to 8 of 8

Thread: Spring Data JPA and Spring Data MongoDB Integration Hell

  1. #1
    Join Date
    Dec 2010
    Posts
    315

    Default [RESOLVED] Spring Data JPA and Spring Data MongoDB Integration Hell

    Issue has been RESOLVED

    I have a stand-alone web application that uses Spring Data JPA 1.0.0.RC1. It works. But when I use the 1.0.0.RELEASE I get the dreaded:
    Code:
    java.util.NoSuchElementException
    I have to stick with 1.0.0.RC1 for the meantime. See http://forum.springsource.org/showth...g-Data-JPA-bug.

    Now, I have another web application that uses Spring Data MongoDB 1.0.0.M3. It works. It's an update for my tutorials I've written: for native Spring MVC and MongoDB integration, 1.0.0.M1, M2. See here http://krams915.blogspot.com/2011/04...for-100m2.html

    The problem starts when I combine both Spring Data JPA and Spring Data MongoDB in one web application. The problem is with the spring-data-commons-core dependency

    • spring-data-mongodb 1.0.0.M3 uses spring-data-commons-core 1.1.0.M1
    • spring-data-jpa 1.0.0.RELEASE uses spring-data-commons-core 1.1.0.RELEASE


    When these two Spring Data JPA and Mongo are combined I get the following exception:

    Code:
    Caused by: java.lang.ClassNotFoundException: org.springframework.data.repository.support.RepositoryFactoryBeanSupport
    It turns out the package structure of spring-data-commons-core 1.1.0.RELEASE has changed from1.1.0.M1. The RepositoryFactoryBeanSupport is now under org.springframework.data.repository.support.core (if I remember exactly).

    But my point here it's in a different package. Hence, when using Maven, only one of these versions will be included. The other one will be excluded.

    Since Maven excludes spring-data-commons-core 1.1.0.M1, Spring Data MongoDB can no longer find the RepositoryFactoryBeanSupport in the expected package, and therefore the exception.

    Okay, so I tried using the latest Spring Data snapshots using Maven:

    Code:
    <spring.data.jpa.version>1.0.0.BUILD-SNAPSHOT</spring.data.jpa.version>
    <spring.data.mongo.version>1.0.0.BUILD-SNAPSHOT</spring.data.mongo.version>
    It turns out Spring Data MongoDB 1.0.0.BUILD-SNAPSHOT is using an updated version of spring-data-commons-core. It's now using spring-data-commons-core 1.2.0.BUILD-SNAPSHOT! While Spring Data JPA 1.0.0.BUILD-SNAPSHOT uses spring-data-commons-core 1.1.0.RC1!

    So now we got a conflict again. And when I run my web app, I no longer get the missing RepositoryFactoryBeanSupport class. However, I'm not sure if that has been resolved entirely because the error I'm getting now is again the dreaded

    Code:
    java.util.NoSuchElementException
    And the funny thing is I'm back to where I started at. I have to revert back to Spring Data JPA 1.0.0.RC1 for the meantime AND abandon MongoDB integration. See
    http://forum.springsource.org/showth...g-Data-JPA-bug.

    So now I have two web apps using two different Spring Data: JPA on one hand, Mongo on the other hand.

    I need a solution and explanation for the following:

    1. When using the latest Spring Data JPA 1.0.0.RELEASE, I get the exception: java.util.NoSuchElementException. Take note, I'm not the only who's getting this error. See
    http://forum.springsource.org/showth...g-Data-JPA-bug.

    2. How can I combine Spring Data JPA and MongoDB without conflict with spring-data-commons-core dependency? I do find it ironic that when we say core it should mean the common base dependency. It's like two projects where one depends on Spring 2 and the other on Spring 3.

    3. Why is the progress from spring-data-commons-core faster in MongoDB than in JPA? Related to question #2, shouldn't they always have the same version? Same question applies to all other Spring Data projects that rely on spring-data-commons-core

    Thank you for reading
    Last edited by skram; Aug 22nd, 2011 at 07:25 AM. Reason: Resolved

  2. #2
    Join Date
    Dec 2010
    Posts
    315

    Default

    I've posted a JIRA regarding the exception NoSuchElementException at https://jira.springsource.org/browse/DATAJPA-90

    However my other issues are still unresolved. If someone has the knowledge, please share.

  3. #3
    Join Date
    Dec 2010
    Posts
    315

    Default

    Here's some updates. I've managed to make Spring Data JPA and Spring Data Mongo to co-exist by using the latest Maven build snapshots:

    Code:
    <spring.data.jpa.version>1.0.0.BUILD-SNAPSHOT</spring.data.jpa.version>
    <spring.data.mongo.version>1.0.0.BUILD-SNAPSHOT</spring.data.mongo.version>
    Maven automatically excluded spring-data-commons-core 1.2.0 BUILD-SNAPSHOT from being included. Instead it used the dependency version from Spring Data JPA: spring-data-commons-core 1.1.0 RC1

    I've verified that the Mongo database has been populated by checking the Mongo shell.

    However, to make all this work, I have to turn off all queries to JPA that uses Pageable as arguments; otherwise, I get the error:

    Code:
    java.util.NoSuchElementException
    This means I can't do any JPA query that uses Pageable. I don't think it's Mongo's fault but rather it's JPA.

  4. #4
    Join Date
    Dec 2010
    Posts
    315

    Default

    Additional updates:

    I've updated my scheduler so that instead of retrieving messages via Spring Data JPA, it now uses Spring Data Mongo:

    My service scheduler has a simple method:
    Code:
    @Override
    	List<Person> persons = personService.getAll();
    		for (Person person : persons) {
    			logger.debug(person);
    	}
    It prints out the person's info every 5 seconds. (I didn't include the declaration of the scheduler)


    Now, I want to verify if the Pageable feature is really causing the issue. I want to know if this bug is related with Spring Data JPA only or not.

    So I changed my code to
    Code:
    @Override
    	List<Person> persons = personService.getAll(new PageRequest(0,1));
    		for (Person person : persons) {
    			logger.debug(person);
    	}
    By the way personService is a wrapper to the PersonRepository.

    And right after I run my application, I get the same exception as with the JPA version!

    Code:
    [DEBUG] [scheduler-2 01:00:42] (ErrorLogAspect.java:logAround:43) Error caught...saving to db log: java.util.NoSuchElementException
    [ERROR] [scheduler-2 01:00:42] (TaskUtils.java:handleError:95) Unexpected error occurred in scheduled task.
    java.lang.NullPointerException
    	at org.krams.tutorial.aop.ErrorLogAspect.logAround(ErrorLogAspect.java:46)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621)
    	at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610)
    	at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:65)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    	at $Proxy128.post(Unknown Source)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:64)
    	at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:53)
    	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
    	at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)
    	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
    	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)
    	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:180)
    	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:204)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    	at java.lang.Thread.run(Thread.java:662)
    My initial conclusion here is that the issue is related with the spring-data-commons-core!

  5. #5
    Join Date
    Dec 2010
    Posts
    315

    Thumbs up

    All of my problems have been resolved by using the latest snapshot build of Spring Data JPA:
    Code:
    <spring.data.jpa.version>1.1.0.BUILD-SNAPSHOT</spring.data.jpa.version>
    I can now use Spring Data Mongo:
    Code:
    <spring.data.mongo.version>1.0.0.BUILD-SNAPSHOT</spring.data.mongo.version>
    Both projects now use the latest spring-data-commons-core-1.2.0.BUILD-SNAPSHOT

    See JIRA https://jira.springsource.org/browse/DATAJPA-90
    Last edited by skram; Aug 22nd, 2011 at 07:31 AM.

  6. #6

    Default

    Wow, tnx for your diligence!

  7. #7
    Join Date
    Nov 2005
    Location
    US of A
    Posts
    43

    Default

    I'm facing similar problems, IMHO snapshots are a no-no for going to production.

  8. #8
    Join Date
    Oct 2007
    Posts
    142

    Default

    Hi

    I am still having the same problem:
    spring-data-jpa : 1.0.3.RELEASE
    spring-data-commons-core : 1.2.1.RELEASE
    spring-data-mongodb : 1.0.1.RELEASE

    Caused by: java.lang.NoSuchMethodError: org.springframework.data.repository.query.parser.P art.getProperty()Lorg/springframework/data/repository/query/parser/Property;
    at org.springframework.data.jpa.repository.query.JpaQ ueryCreator.toPredicate(JpaQueryCreator.java:163)

Posting Permissions

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