Announcement Announcement Module
Collapse
No announcement yet.
JPA with Spring 2.0: Does it work outside integration tests? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JPA with Spring 2.0: Does it work outside integration tests?

    I'm starting a new project and thought this would be a great opportunity to use JPA with the new Spring2.0 that just got released.

    Got my hands on two articles that show how to use the technology and thought it would be a piece of cake to get things running. Unfortunately, while I can get things to work in a test environment, I haven't been successful yet outside of integration tests.

    It should be trivial to figure out what's wrong, but my few posts haven't generated an answer yet. Here is my last plea before giving up.

    -----
    Interface21 team blog: Getting Started with JPA in Spring 2.0
    http://blog.interface21.com/main/200...a-in-spring-20

    Integration tests work perfectly. Trying to make it work outside of integration
    test fails with: "Object is not a known entity type." See comments at the
    end of the blog for details.

    -----
    Sing Li article: Introduction to Spring 2 and JPA
    http://www-128.ibm.com/developerwork...spring2-i.html

    Integration tests work perfectly. Trying to make it work in Tomcat (following religiously the instructions given), results in a "java.lang.IllegalAccessError" exception. Details included below.

    -----
    So, is there someone out there who has been successful using JPA with Spring 2.0 that could explain why the above 2 examples do not work outside of integration tests, or that could share a simple webapp that does work?

    Thanks,

    Paul

    -----
    Exception for Sing Li's sample app on DeveloperWorks:

    org.springframework.web.util.NestedServletExceptio n
    : Handler processing failed; nested exception is java.lang.IllegalAccessError: class sun.reflect.GeneratedConstructorAccessor15 cannot access its superclass sun.reflect.ConstructorAccessorImpl
    org.springframework.web.servlet.DispatcherServlet. doDispatch
    (DispatcherServlet.java:846)
    org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:736)
    org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:396)
    org.springframework.web.servlet.FrameworkServlet.d oGet
    (FrameworkServlet.java:350)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:689)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:802)

    root cause

    java.lang.IllegalAccessError
    : class sun.reflect.GeneratedConstructorAccessor15 cannot access its superclass sun.reflect.ConstructorAccessorImpl
    sun.misc.Unsafe.defineClass(Native Method)
    sun.reflect.ClassDefiner.defineClass(ClassDefiner. java
    :45)
    sun.reflect.MethodAccessorGenerator$1.run(MethodAc cessorGenerator.java:381)
    java.security.AccessController.doPrivileged(Native Method)
    sun.reflect.MethodAccessorGenerator.generate(Metho dAccessorGenerator.java
    :377)
    sun.reflect.MethodAccessorGenerator.generateConstr uctor(MethodAccessorGenerator.java:76)
    sun.reflect.NativeConstructorAccessorImpl.newInsta nce(NativeConstructorAccessorImpl.java:30)
    sun.reflect.DelegatingConstructorAccessorImpl.newI nstance
    (DelegatingConstructorAccessorImpl.java:27)
    java.lang.reflect.Constructor.newInstance(Construc tor.java:494)
    oracle.toplink.essentials.internal.security.Privil egedAccessHelper.invokeConstructor(PrivilegedAcces sHelper.java
    :295)
    oracle.toplink.essentials.internal.descriptors.Ins tantiationPolicy.buildNewInstanceUsingDefaultConst ructor(InstantiationPolicy.java:136)
    oracle.toplink.essentials.internal.descriptors.Ins tantiationPolicy.buildNewInstance
    (InstantiationPolicy.java:111)
    oracle.toplink.essentials.internal.descriptors.Obj ectBuilder.buildNewInstance(ObjectBuilder.java:324 )
    oracle.toplink.essentials.descriptors.copying.Inst antiationCopyPolicy.buildClone
    (InstantiationCopyPolicy.java:37)
    oracle.toplink.essentials.descriptors.copying.Abst ractCopyPolicy.buildWorkingCopyClone(AbstractCopyP olicy.java:49)
    oracle.toplink.essentials.internal.descriptors.Obj ectBuilder.instantiateWorkingCopyClone
    (ObjectBuilder.java:1988)
    oracle.toplink.essentials.internal.sessions.UnitOf WorkImpl.cloneAndRegisterObject(UnitOfWorkImpl.jav a:641)
    oracle.toplink.essentials.internal.sessions.UnitOf WorkIdentityMapAccessor.getAndCloneCacheKeyFromPar ent
    (UnitOfWorkIdentityMapAccessor.java:152)
    oracle.toplink.essentials.internal.sessions.UnitOf WorkIdentityMapAccessor.getFromIdentityMap(UnitOfW orkIdentityMapAccessor.java:90)
    oracle.toplink.essentials.internal.sessions.Identi tyMapAccessor.getFromIdentityMap
    (IdentityMapAccessor.java:295)
    oracle.toplink.essentials.internal.sessions.UnitOf WorkImpl.registerExistingObject(UnitOfWorkImpl.jav a:3055)
    oracle.toplink.essentials.internal.sessions.UnitOf WorkImpl.registerExistingObject
    (UnitOfWorkImpl.java:3004)
    oracle.toplink.essentials.queryframework.ObjectBui ldingQuery.registerIndividualResult(ObjectBuilding Query.java:319)
    oracle.toplink.essentials.internal.descriptors.Obj ectBuilder.buildWorkingCopyCloneNormally
    (ObjectBuilder.java:441)
    oracle.toplink.essentials.internal.descriptors.Obj ectBuilder.buildObjectInUnitOfWork(ObjectBuilder.j ava:406)
    oracle.toplink.essentials.internal.descriptors.Obj ectBuilder.buildObject(ObjectBuilder.java
    :372)
    oracle.toplink.essentials.queryframework.ReportQue ryResult.processItem(ReportQueryResult.java:205)
    oracle.toplink.essentials.queryframework.ReportQue ryResult.buildResult(ReportQueryResult.java:167)
    oracle.toplink.essentials.queryframework.ReportQue ryResult
    .<init>(ReportQueryResult.java:83)
    oracle.toplink.essentials.queryframework.ReportQue ry.buildObject(ReportQuery.java:579)
    oracle.toplink.essentials.queryframework.ReportQue ry.buildObjects(ReportQuery.java:628)

    oracle.toplink.essentials.queryframework.ReportQue ry.executeDatabaseQuery(ReportQuery.java:776)
    oracle.toplink.essentials.queryframework.DatabaseQ uery.execute(DatabaseQuery.java:609)
    oracle.toplink.essentials.queryframework.ObjectLev elReadQuery.execute
    (ObjectLevelReadQuery.java:677)
    oracle.toplink.essentials.queryframework.ObjectLev elReadQuery.executeInUnitOfWork(ObjectLevelReadQue ry.java:731)
    oracle.toplink.essentials.internal.sessions.UnitOf WorkImpl.internalExecuteQuery
    (UnitOfWorkImpl.java:2218)
    oracle.toplink.essentials.internal.sessions.Abstra ctSession.executeQuery(AbstractSession.java:937)
    oracle.toplink.essentials.internal.sessions.Abstra ctSession.executeQuery(AbstractSession.java
    :909)
    oracle.toplink.essentials.internal.ejb.cmp3.base.E JBQueryImpl.executeReadQuery(EJBQueryImpl.java:346 )
    oracle.toplink.essentials.internal.ejb.cmp3.base.E JBQueryImpl.getResultList(EJBQueryImpl.java:447)
    org.springframework.orm.jpa.JpaTemplate$9.doInJpa
    (JpaTemplate.java:305)
    org.springframework.orm.jpa.JpaTemplate.execute(Jp aTemplate.java:183)
    org.springframework.orm.jpa.JpaTemplate.executeFin d(JpaTemplate.java:150)
    org.springframework.orm.jpa.JpaTemplate.find
    (JpaTemplate.java:297)
    org.springframework.orm.jpa.JpaTemplate.find(JpaTe mplate.java:293)
    com.ibm.dw.spring2.EmployeeDAO.findAll(EmployeeDAO .java:15)
    com.ibm.dw.spring2.web.MainController.handleReques tInternal
    (MainController.java:19)
    org.springframework.web.servlet.mvc.AbstractContro ller.handleRequest(AbstractController.java:153)
    org.springframework.web.servlet.mvc.SimpleControll erHandlerAdapter.handle(SimpleControllerHandlerAda pter.java
    :45)
    org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:806)
    org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:736)
    org.springframework.web.servlet.FrameworkServlet.p rocessRequest
    (FrameworkServlet.java:396)
    org.springframework.web.servlet.FrameworkServlet.d oGet(FrameworkServlet.java:350)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:689)
    javax.servlet.http.HttpServlet.service
    (HttpServlet.java:802)

  • #2
    It seems that you use SimpleLoadTimeWeaver - however SLTW doesn't work with webapps. When using SLTW I've got a similar exception. Try ReflectiveLoadTimeWeaver or InstrumentLoadTimeWeaver (spring-agent.jar)

    Comment


    • #3
      Thanks for the tip. I switched to ReflectiveLoadTimeWeaver and I now get the following exception:


      java.lang.IllegalArgumentException: An exception occured while creating a query in EntityManager
      oracle.toplink.essentials.internal.ejb.cmp3.Entity ManagerImpl.createQuery(EntityManagerImpl.java:180 )
      sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
      sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
      java.lang.reflect.Method.invoke(Method.java:585)
      org.springframework.orm.jpa.ExtendedEntityManagerC reator$ExtendedEntityManagerInvocationHandler.invo ke(ExtendedEntityManagerCreator.java:237)
      $Proxy6.createQuery(Unknown Source)
      sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
      sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
      java.lang.reflect.Method.invoke(Method.java:585)
      org.springframework.orm.jpa.JpaTemplate$CloseSuppr essingInvocationHandler.invoke(JpaTemplate.java:39 2)
      $Proxy7.createQuery(Unknown Source)
      org.springframework.orm.jpa.JpaTemplate$9.doInJpa( JpaTemplate.java:299)
      org.springframework.orm.jpa.JpaTemplate.execute(Jp aTemplate.java:183)
      org.springframework.orm.jpa.JpaTemplate.executeFin d(JpaTemplate.java:150)
      org.springframework.orm.jpa.JpaTemplate.find(JpaTe mplate.java:297)
      org.springframework.orm.jpa.JpaTemplate.find(JpaTe mplate.java:293)
      com.ibm.dw.spring2.EmployeeDAO.findAll(EmployeeDAO .java:15)
      com.ibm.dw.spring2.web.MainController.handleReques tInternal(MainController.java:19)


      Paul

      Comment


      • #4
        Well, finally got it to work.

        Trick is to use InstrumentationLoadTimeWeaver along with the following parameter:
        -javaagent:<path-to-spring>\dist\weavers\spring-agent.jar

        Many thanks ghofmann for helping me figure it out. I owe you one!

        Paul

        Comment


        • #5
          Sorry for the hard time pauls - the documentation has been updated some time ago and hopefully, things will be clear once it will be released.
          As for integration testing I would recommend to use the classes provided by Spring since they eliminate the need for a weaver and thus improve performance.

          Comment


          • #6
            Originally posted by pauls View Post
            Well, finally got it to work.

            Trick is to use InstrumentationLoadTimeWeaver along with the following parameter:
            -javaagent:<path-to-spring>\dist\weavers\spring-agent.jar

            Many thanks ghofmann for helping me figure it out. I owe you one!

            Paul
            I have the same problem as Pauls. But I can't figure out how it works. I wonder where and how can I set the parameter?

            Comment

            Working...
            X