Results 1 to 8 of 8

Thread: Problems with load time weaving and @Configurable

  1. #1
    Join Date
    May 2005
    Posts
    21

    Default Problems with load time weaving and @Configurable

    Ack, I need some help. I've gone over the 2.1 documentation (sections 6.8.1 and 6.8.4) several times and I cannot seem to get @Configurable working with load-time-weaving. There has to be something that I'm missing in my configuration but I cannot spot it. If anyone out there would be kind enough to go over my config and see if you can spot anytyhing, I'd be very grateful for the help.


    JPA Entity

    Code:
    @Configurable
    @Entity
    public class StandardMenu extends BaseStandardMenu {
        @Transient
        StandardMenuDao standardMenuDao;
    	
        public void setStandardMenuDao(StandardMenuDao standardMenuDao) {
            this.standardMenuDao = standardMenuDao;
        }
    
    
        @PrePersist
        @PreUpdate
        void doAudit() {
            if (id != null) {
                StandardMenu menu = standardMenuDao.getById(id);
                audits.add(new StandardMenuAudit(menu));
            }
            modifiedBy = "foo"; // TODO replace with real value
            modifiedDate = new Date();
        }
    }
    data-context.xml

    Code:
    <context:spring-configured/>
    <context:load-time-weaver/>
    <bean id="standardMenu" class="com.mycompany.menu.data.model.StandardMenu" scope="prototype">
    	<property name="standardMenuDao" ref="standardMenuDao"/>
    </bean>
     <bean id="standardMenuDao" class="com.mycompany.menu.data.dao.JpaStandardMenuDaoImpl"/>
    META-INF/aop.xml

    Code:
    <!DOCTYPE aspectj PUBLIC
            "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">
    <aspectj>
        <weaver>
            <include within="com.mycompany.menu.data.model.*"/>
        </weaver>
        <aspects>
            <aspect name="org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect"/>
        </aspects>
    </aspectj>
    Dependencies:

    Code:
    spring-2.1-m3.jar
    spring-aspects-2.1-m3.jar
    spring-agent-2.1-m3.jar
    aspectjweaver-1.5.3.jar
    aspectjrjt-1.5.3.jar


    In the JPA Entity above, standardMenuDao is always null according to my unit tests.




    - edit -

    I forgot to mention that I'm starting the jvm with the javaagent:

    Code:
    -javaagent:C:\dev\server\jboss-4.2.1.GA\lib\spring-agent-2.1-m3.jar
    I get a nasty exception if I do not:

    Code:
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.context.weaving.AspectJWeavingEnabler#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loadTimeWeaver': Initialization of bean failed; nested exception is java.lang.IllegalStateException: ClassLoader [sun.misc.Launcher$AppClassLoader] does NOT provide an 'addTransformer(ClassFileTransformer)' method. Specify a custom LoadTimeWeaver or start your Java virtual machine with Spring's agent: -javaagent:spring-agent.jar
    Last edited by mcantrell; Sep 11th, 2007 at 12:33 PM.

  2. #2
    Join Date
    Jul 2006
    Location
    Kolkata, India
    Posts
    217

    Default

    Have you been able to fix this problem ? I am also getting the same problem using JPA with Hibernate and Spring @Configurable.

    - Debasish

  3. #3
    Join Date
    Jul 2006
    Location
    London
    Posts
    500

    Default

    I followed this blog and had no problems:
    http://chris-richardson.blog-city.co...es_into_en.htm
    Regards,
    James

  4. #4
    Join Date
    Jul 2006
    Location
    Kolkata, India
    Posts
    217

    Default

    Quote Originally Posted by jamesclinton View Post
    I followed this blog and had no problems:
    http://chris-richardson.blog-city.co...es_into_en.htm
    In my case I am facing the same error when I try to introduce another aspect of mine along with AnnotationBeanConfigurerAspect in aop.xml. The error that I am getting is as follows :

    Code:
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor#0' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.config.internalTransactionAdvisor': Cannot create inner bean '(inner bean)' of type [org.springframework.transaction.interceptor.TransactionInterceptor] while setting bean property 'transactionInterceptor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting bean property 'entityManagerFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: org.hibernate.InstantiationException: could not instantiate test objectorg.dg.domain.entity.Project
    Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [org.dg.inf.persistence.impl.jpa.hibernate.PlainJpaRepository] for bean with name 'repoImpl' defined in class path resource [applicationContext.xml]: problem with class file or dependent class; nested exception is java.lang.LinkageError: loader (instance of  org/springframework/context/support/ContextTypeMatchClassLoader): attempted  duplicate class definition for name: "org/dg/inf/persistence/impl/jpa/hibernate/PlainJpaRepository"
    The moment I remove the aspect entry from aop.xml, it works fine. I am using Spring 2.1 M4. Any help will be appreciated.

    And here is the application context xml file :

    HTML Code:
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:p="http://www.springframework.org/schema/p"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xmlns:context="http://www.springframework.org/schema/context"
           xsi:schemaLocation="
           http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.1.xsd">
           
       
       <context:spring-configured/>
       <tx:annotation-driven transaction-manager="transactionManager"/>
       
       <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
       
       <bean id="repoImpl"
             class="org.dg.inf.persistence.impl.jpa.hibernate.PlainJpaRepository">
       </bean>
       
       
    
       <bean id="organizationRepository"
             class="org.dg.domain.repository.impl.jpa.hibernate.OrganizationRepository"
             lazy-init="true"
             p:repositoryImpl-ref="repoImpl"/>
             
      
       <bean id="entityManagerFactory" 
             class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
             <property name="dataSource" ref="dataSource"/>
             <property name="jpaVendorAdapter">
               <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
                     p:showSql="true"
                     p:generateDdl="true"/>
             </property>
       </bean>
       
       <bean id="dataSource" 
             class="org.springframework.jdbc.datasource.DriverManagerDataSource"
             p:driverClassName="org.hsqldb.jdbcDriver"
             p:url="jdbc:hsqldb:mem:testdb/"
             p:username="sa"
             p:password="" />
    
       <bean id="transactionManager" 
             class="org.springframework.orm.jpa.JpaTransactionManager"
             p:entityManagerFactory-ref="entityManagerFactory"
             p:dataSource-ref="dataSource" />
             
       <bean id="databaseSetup"
    		 class="org.dg.domain.repository.impl.jpa.hibernate.RepositoryTests$DatabaseSetup" />
    	
       <!-- this switches on the load-time weaving -->
       <context:load-time-weaver/>	
       <bean class="org.dg.domain.entity.Project" 
             scope="prototype"
             p:organizationRepository-ref="organizationRepository" />
      
    </beans>
    Cheers.
    - Debasish

  5. #5
    Join Date
    Jun 2006
    Location
    SF Bay Area, California
    Posts
    524

    Default

    If you get a chance, can you try with the latest nightly build (20071010-263 or later). I have fixed a bug (http://opensource.atlassian.com/proj...rowse/SPR-3873) that might affect the behavior you are seeing.

    -Ramnivas
    Ramnivas Laddad (Follow me on Twitter)
    AspectJ in Action: Enterprise AOP with Spring Applications (2nd edition). Now available!

  6. #6
    Join Date
    Jul 2006
    Location
    Kolkata, India
    Posts
    217

    Default

    Thanks Ramnivas .. I will try it out and let u know ..

    Cheers.
    - Debasish

  7. #7
    Join Date
    Jul 2006
    Location
    Kolkata, India
    Posts
    217

    Default

    Quote Originally Posted by ramnivas View Post
    If you get a chance, can you try with the latest nightly build (20071010-263 or later). I have fixed a bug (http://opensource.atlassian.com/proj...rowse/SPR-3873) that might affect the behavior you are seeing.
    With the new snapshot of Spring, I am getting a different error, which may be a bug with AspectJ (not sure though!). Here is the stack trace.

    Code:
    javax.persistence.PersistenceException: org.hibernate.InstantiationException: Could not instantiate entity: org.dg.domain.entity.Project
    	at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:630)
    	at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:75)
    	at org.dg.inf.persistence.impl.jpa.hibernate.PlainJpaRepository.read(PlainJpaRepository.java:74)
    	at org.dg.inf.persistence.Repository.read(Repository.java:24)
    	at org.dg.domain.repository.impl.jpa.hibernate.ProjectRepository.byName(ProjectRepository.java:43)
    	at org.dg.domain.repository.impl.jpa.hibernate.RepositoryTests.testAllocation(RepositoryTests.java:343)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at org.springframework.test.context.junit4.SpringTestMethod.invoke(SpringTestMethod.java:198)
    	at org.springframework.test.context.junit4.SpringMethodRoadie.runTestMethod(SpringMethodRoadie.java:273)
    	at org.springframework.test.context.junit4.SpringMethodRoadie$2.run(SpringMethodRoadie.java:206)
    	at org.springframework.test.context.junit4.SpringMethodRoadie.runBeforesThenTestThenAfters(SpringMethodRoadie.java:253)
    	at org.springframework.test.context.junit4.SpringMethodRoadie.runWithRepetitions(SpringMethodRoadie.java:233)
    	at org.springframework.test.context.junit4.SpringMethodRoadie.runTest(SpringMethodRoadie.java:202)
    	at org.springframework.test.context.junit4.SpringMethodRoadie.run(SpringMethodRoadie.java:143)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:168)
    	at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
    	at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
    	at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:26)
    	at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:36)
    	at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
    	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
    	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
    Caused by: org.hibernate.InstantiationException: Could not instantiate entity: org.dg.domain.entity.Project
    	at org.hibernate.tuple.PojoInstantiator.instantiate(PojoInstantiator.java:91)
    	at org.hibernate.tuple.PojoInstantiator.instantiate(PojoInstantiator.java:100)
    	at org.hibernate.tuple.entity.AbstractEntityTuplizer.instantiate(AbstractEntityTuplizer.java:351)
    	at org.hibernate.persister.entity.AbstractEntityPersister.instantiate(AbstractEntityPersister.java:3606)
    	at org.hibernate.impl.SessionImpl.instantiate(SessionImpl.java:1275)
    	at org.hibernate.impl.SessionImpl.instantiate(SessionImpl.java:1264)
    	at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1299)
    	at org.hibernate.loader.Loader.getRow(Loader.java:1206)
    	at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:580)
    	at org.hibernate.loader.Loader.doQuery(Loader.java:701)
    	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
    	at org.hibernate.loader.Loader.doList(Loader.java:2220)
    	at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
    	at org.hibernate.loader.Loader.list(Loader.java:2099)
    	at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
    	at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
    	at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
    	at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
    	at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
    	at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:66)
    	... 27 more
    Caused by: java.lang.reflect.InvocationTargetException
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    	at java.lang.reflect.Constructor.newInstance(Unknown Source)
    	at org.hibernate.tuple.PojoInstantiator.instantiate(PojoInstantiator.java:88)
    	... 46 more
    Caused by: java.lang.NoSuchFieldError: ajc$cflowCounter$0
    	at org.dg.domain.entity.Project.<init>(Project.java:131)
    	... 51 more
    Cheers.
    - Debasish

  8. #8
    Join Date
    Aug 2007
    Posts
    8

    Default

    Quote Originally Posted by debasishg View Post
    With the new snapshot of Spring, I am getting a different error, which may be a bug with AspectJ (not sure though!).
    Indeed, it may be a recently fixed AspectJ bug:

    see https://bugs.eclipse.org/bugs/show_bug.cgi?id=230134

    You may want to try out the latest development build of AspectJ to see if this problem is fixed.

    Best Regards,
    Larry

Posting Permissions

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