Announcement Announcement Module
Collapse

Spring Dynamic Modules forum decommissioned in favor of Eclipse Gemini Blueprint

With the official first release of Eclipse Gemini Blueprint shipped, the migration of the Spring Dynamic Modules code base to the Eclipse Foundation, as part of the Gemini project, has been completed.

As such, this forum has been decommissioned in favour of the Eclipse Gemini forums.
See more
See less
Spring DM and Eclipselink entity weaving not working. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring DM and Eclipselink entity weaving not working.

    Hi,

    I have been searching for the helpful posts for the issue I have related to spring dm and eclipslink entity weaving but couldn't find any.

    We have a web project which is working fine in a standalone non-dm environment. We are using extJS (view layer), struts 2 (action layer), spring (service layer) and eclipselink (persistence layer).

    Now we have a need to port this project in an OSGI environment. I am trying to use spring DM as a first step. Here I am able to setup the spring dm-target platform with spring-dm modules and eclipselink dynamic modules. However as part of the entitymanagerfactory definition as shown below, we are using loadtimeweaver.

    HTML Code:
    	<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    		<property name="persistenceUnitManager"
    			ref="persistenceUnitManager" />
    		<property name="persistenceUnitName"
    			value="AG_CLINICAL_MAIN_DS" />
    		<property name="dataSource" ref="dataSource" />
    		<property name="loadTimeWeaver">
    			<bean
    class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
    		</property>
    		<property name="jpaVendorAdapter">
    			<bean
    				class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
    				<property name="databasePlatform" value="oracle" />
    				<property name="generateDdl" value="true" />
    				<property name="showSql" value="true" />
    			</bean>
    		</property>
    	</bean>
    However I am getting an error for javaagent to be provided for the loadtimeweaver. Earlier we used to specify the javaagent for the java process, however in case of osgi I am not able to specify the javaagent since the classloading mechanism in OSGI is entirely different.

    Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'entityManagerFactory' defined in URL [bundleentry://10/META-INF/spring/agclinicalservices.xml]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Cannot apply class transformer without LoadTimeWeaver specified
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1338)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:473)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory$1.run(AbstractAutowireC apableBeanFactory.java:409)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:380)
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 64)
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:222)
    at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:261 )
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:185)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:164)
    at org.springframework.orm.jpa.support.PersistenceAnn otationBeanPostProcessor.findDefaultEntityManagerF actory(PersistenceAnnotationBeanPostProcessor.java :507)
    at org.springframework.orm.jpa.support.PersistenceAnn otationBeanPostProcessor.findEntityManagerFactory( PersistenceAnnotationBeanPostProcessor.java:473)
    at org.springframework.orm.jpa.support.PersistenceAnn otationBeanPostProcessor$PersistenceElement.resolv eEntityManager(PersistenceAnnotationBeanPostProces sor.java:599)
    at org.springframework.orm.jpa.support.PersistenceAnn otationBeanPostProcessor$PersistenceElement.getRes ourceToInject(PersistenceAnnotationBeanPostProcess or.java:570)
    at org.springframework.beans.factory.annotation.Injec tionMetadata$InjectedElement.inject(InjectionMetad ata.java:192)
    at org.springframework.beans.factory.annotation.Injec tionMetadata.injectMethods(InjectionMetadata.java: 117)
    at org.springframework.orm.jpa.support.PersistenceAnn otationBeanPostProcessor.postProcessPropertyValues (PersistenceAnnotationBeanPostProcessor.java:321)
    ... 50 more
    Caused by: java.lang.IllegalStateException: Cannot apply class transformer without LoadTimeWeaver specified
    at org.springframework.orm.jpa.persistenceunit.Spring PersistenceUnitInfo.addTransformer(SpringPersisten ceUnitInfo.java:78)
    at org.eclipse.persistence.jpa.PersistenceProvider.cr eateContainerEntityManagerFactory(PersistenceProvi der.java:227)
    at org.springframework.orm.jpa.LocalContainerEntityMa nagerFactoryBean.createNativeEntityManagerFactory( LocalContainerEntityManagerFactoryBean.java:224)
    at com.arisglobal.aglite.jpa.AGEntityManagerFactoryBe an.createNativeEntityManagerFactory(AGEntityManage rFactoryBean.java:23)
    at org.springframework.orm.jpa.AbstractEntityManagerF actoryBean.afterPropertiesSet(AbstractEntityManage rFactoryBean.java:291)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:1369)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1335)
    ... 66 more

    Could somebody point me to a solution or the right way of doing this?

    Thanks in advance,
    Shashi

  • #2
    Maybe the LTW is not visible (i.e. properly imported by your bundle). Could you try using dm Server first to see what results you get?

    Comment


    • #3
      Maybe this is related to your issue:

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

      Comment


      • #4
        Thanks much Martin and Costin,

        I will try the solution of EquinoxLoadTimeWeaver and post my experience.

        Regards,
        Shashi

        Comment


        • #5
          Let me know if you need any help. The setup for Equinox Aspects (and the EquinoxLoadTimeWeaver) is a bit tricky, so let me know when you need help.

          Cheers,
          -Martin

          Comment


          • #6
            Hi Martin,

            I have tried to setup the springweaver plugin. The plugin is started. However I still am facing the same problem. I have mailed you the details at your [email protected] mailid.

            Please let me know your comments.

            Regards,
            Shashi

            Comment


            • #7
              Hi Martin,

              I was able to solve the problem I described earlier. The solution was to use the

              HTML Code:
              <context:load-time-weaver weaver-class="org.eclipse.equinox.weaving.springweaver.EquinoxAspectsLoadTimeWeaver"/>
              I had used

              HTML Code:
              <property name="loadTimeWeaver">
              <bean				class="org.eclipse.equinox.weaving.springweaver.EquinoxAspectsLoadTimeWeaver" />
              </property>
              which caused the 'LoadTimeWeaver should be provided' problem.

              Currently facing another problem and trying to find the solution. Actually I don't understand in OSGI environment how will the database driver be loaded
              HTML Code:
              Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 1.1.0.r3634): org.eclipse.persistence.exceptions.DatabaseException
              Internal Exception: java.sql.SQLException: No suitable driver
              Error Code: 0
              	at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:298)
              	at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:138)
              	at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:94)
              	at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
              	at org.eclipse.persistence.internal.databaseaccess.DatasourceAccessor.connectInternal(DatasourceAccessor.java:324)
              	at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.connectInternal(DatabaseAccessor.java:265)
              	at org.eclipse.persistence.internal.databaseaccess.DatasourceAccessor.connect(DatasourceAccessor.java:407)
              	at org.eclipse.persistence.sessions.server.ConnectionPool.buildConnection(ConnectionPool.java:130)
              	at org.eclipse.persistence.sessions.server.ExternalConnectionPool.startUp(ExternalConnectionPool.java:118)
              	at org.eclipse.persistence.sessions.server.ServerSession.connect(ServerSession.java:502)
              	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.login(DatabaseSessionImpl.java:629)
              	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:229)
              	at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:255)
              	... 54 more
              Caused by: java.sql.SQLException: No suitable driver
              	at java.sql.DriverManager.getConnection(DriverManager.java:545)
              	at java.sql.DriverManager.getConnection(DriverManager.java:140)
              	at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:174)
              	at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:165)
              	at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:149)
              	at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:128)
              	at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:135)
              	... 65 more
              Please let me know of any clue you have.

              Regards,
              Shashi

              Comment


              • #8
                Hi,

                I resolved the problem I listed in my previous post.

                The problem was with the database driver jar not being found in the classpath. Since spring-jdbc module does the job of registering the driver, I had to modify the jdbc module manifest to include the driver jar in the classpath. Also I had to remove the jdbc bundle from the dm-platform I had set.

                However after resolving these problems, I am facing an issue with entitymanager not getting injected.

                In my spring configuration I have PersistenceAnnotationBeanPostProcessor, however it doesn't seem to be working and is not injecting the entity manager in my service bean class.

                HTML Code:
                <bean		class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
                I have following code in my service class.

                .....
                protected EntityManager em;
                .....
                @PersistenceContext
                public void setEntityManager(EntityManager em) {
                String methodName = "setEntityManager(EntityManager em)";
                logger.entering(methodName);
                this.em = em;
                logger.exiting(methodName);
                }

                Hence I get a null pointer exception when I call

                HTML Code:
                em.save(myentity);
                in the service class.

                Please let me know if you have any solution for making this work.

                Thanks in advance,
                Shashi

                Comment


                • #9
                  Hi,

                  Finally I could solve all the issues. The issue about the null entitymanager was resolved when I replaced

                  HTML Code:
                  <bean		class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
                  with

                  HTML Code:
                  <context:annotation-config/>
                  Thanks Martin for your help.

                  Regards,
                  Shashi

                  Comment


                  • #10
                    Hi,

                    Juts for information, I have updated Martin Lippert Springweaver bundle to manage JPA/Eclipselink. Please see at http://angelozerr.wordpress.com/2010...gweaver_step1/ You will find explanation of the problem with Martin Lippert Springweaver and I have tried to explain how I fix it. There is too a sample with JPA/Eclipselink, that I will explain into another post.

                    Regards Angelo

                    Comment

                    Working...
                    X