Announcement Announcement Module
Collapse
No announcement yet.
AOP and Hibernate Dependency Conflict Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • AOP and Hibernate Dependency Conflict

    spring-aop:2.0.2
    hibernate:3.2.1.ga
    tomcat:6.0.10

    As far as I can tell the conflict I've run into has to do with ASM. I've declared a pointcut and aspect using the new schema based AOP approach. This requires both the spring-aop lib as well as aspectj. I'm applying the aspect to a hibernate dao. During my unit tests the version of asm that hibernate depends on was conflicting with the version spring expected. So, I included asm:2.2.3 and that seemed to work.
    However, when deploying to tomcat I get the following cause for an exception:


    nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAd visor': Cannot create inner bean '(inner bean)' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name '(inner bean)': Invocation of init method failed; nested exception is java.lang.AbstractMethodError: org.springframework.core.LocalVariableTableParamet erNameDiscoverer$FindMethodParamNamesClassVisitor. visit(ILjava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/StringV
    Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAd visor': Cannot create inner bean '(inner bean)' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name '(inner bean)': Invocation of init method failed; nested exception is java.lang.AbstractMethodError: org.springframework.core.LocalVariableTableParamet erNameDiscoverer$FindMethodParamNamesClassVisitor. visit(ILjava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/StringV
    Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name '(inner bean)': Invocation of init method failed; nested exception is java.lang.AbstractMethodError: org.springframework.core.LocalVariableTableParamet erNameDiscoverer$FindMethodParamNamesClassVisitor. visit(ILjava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/StringV
    Caused by: java.lang.AbstractMethodError: org.springframework.core.LocalVariableTableParamet erNameDiscoverer$FindMethodParamNamesClassVisitor. visit(ILjava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/StringV
    at org.objectweb.asm.ClassReader.accept(Unknown Source)
    at org.objectweb.asm.ClassReader.accept(Unknown Source)


    Considering that I've had to include the newer asm libraries manually I suspect this may have something to do with it. However, Tomcat is the main difference. I'm not sure what to make of this.

    Any thoughts are greatly appreciated.

    -T

  • #2
    I would try the libs provided by Spring when you download "with dependencies". I have that all working fine!

    Comment


    • #3
      Okay. I am using maven2. So, I excluded the asm libraries from hibernate. These are asm:1.4.3, -utl, etc. I included the newer asm libraries respecively verion 2.2.3. This works in my AbstractDependencyInjectionSpringContextTests unit tests from Eclipse. Deploying to Tomcat now results in the following error:

      ...
      Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'myTxManager' defined in class path resource [applicationContext-dao.xml]: Cannot resolve reference to bean 'mySessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'mySessionFactory' defined in class path resource [applicationContext-dao.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/objectweb/asm/CodeVisitor
      Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'mySessionFactory' defined in class path resource [applicationContext-dao.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/objectweb/asm/CodeVisitor
      Caused by: java.lang.NoClassDefFoundError: org/objectweb/asm/CodeVisitor
      ...

      Clearly the txManager requires an older version of asm. However, using the older version of asm breaks the Eclipse unit tests. Also, the older version results in the errors described previously. When deploying the configuration using the older version of asm I get the following error:

      ...
      Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAd visor': Cannot create inner bean '(inner bean)' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name '(inner bean)': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/objectweb/asm/ClassVisitor
      Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name '(inner bean)': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/objectweb/asm/ClassVisitor
      Caused by: java.lang.NoClassDefFoundError: org/objectweb/asm/ClassVisitor
      at org.springframework.aop.aspectj.AbstractAspectJAdv ice.createParameterNameDiscoverer(AbstractAspectJA dvice.java:368)
      at org.springframework.aop.aspectj.AbstractAspectJAdv ice.bindArgumentsByName(AbstractAspectJAdvice.java :345)
      at org.springframework.aop.aspectj.AbstractAspectJAdv ice.calculateArgumentBindings(AbstractAspectJAdvic e.java:318)
      at org.springframework.aop.aspectj.AbstractAspectJAdv ice.afterPropertiesSet(AbstractAspectJAdvice.java: 284)
      ...

      So you see, spring-aop is incompatible with spring-hibernate. Both rely on separate incompatible versions of asm.

      I believe this is a major conflict. I do not believe that the apring-aop can be combined with spring-hibernate as they both rely on seperate and incompatible versions of asm.

      Comment


      • #4
        As a note, I think cglib might have something to do with all this though I've yet to locate the exact relation.

        Comment


        • #5
          Update. I believe the incompatibility is with the aspectjweaver. It expects asm:2.2.3. Hibernate depends on asm:1.5.3. I can't believe more people haven't encountered this. I'll update this thread as I learn more.

          Comment


          • #6
            It's hibernate's version of cglib. It expects an older version of asm. I tried just overriding this with the newest cglib, but that caused plenty of other failures. Ugh.

            Comment


            • #7
              We use Hibernate 3.2.2 together with Spring 2.0.3 and make full use of the Spring 2.0 AOP capabilities. We simply included the ASM version shipped with Spring and everything works without any problems. We also included all the other libraries we needed, like cglib-nodep, we simply used the ones shipped with Spring.

              I figure that it has something to do with your build, the error comes from Spring so it appears as if the ASM 1.5.3 library instead of the 2.2.3 version is being included in your build/distribution.

              Comment


              • #8
                Yes, I know. If you use everything from spring life is grand. It is not possible for this approach to work across all organizations. Many have adopted standardized practices for code development. Mine requires the use of maven not only during development but also during continuous integration (continuum). We've had project after project without error. This particular project I'm working on is making use of spring-aop and the aspectj style in the xml schema. Up until now everything's been great. this throws a wrench in my whole machine. In all likelihood I'll have to resort to using the old aop style as I haven't got much time left and this has taken too much time as it is. Unfortunately this means the old style spring interceptors...it is what it is.

                Comment


                • #9
                  Now that I think of it, that doesn't guarantee that this will work at all. I may have to revert to an earlier version of spring altogether. In either case, its been a nightmare - the type of nightmare that mvn has by and large done away with...at least in my organization.

                  Comment


                  • #10
                    I haven't worked with maven (1 or 2) but isn't it simply possible to exclude all hibernate referenced libraries and leave just the main hibernate 3.2.x file and use all the needed libraries from the Spring project?

                    Comment


                    • #11
                      I ran into the same problem with hibernate 3.2.2.ga, spring 2.0.3 and m2.

                      To resolve it I excluded the asm:asm-attrs, asm:asm, cglib:cglib deps from Hibernate, excluded cglib:cglib from Spring and added an dependency on cglib:cglib-nodep (version 2.1_3) to my pom.
                      Deployment to tomcat works fine and my dao unit tests run without probs as well.

                      Comment


                      • #12
                        OMG. Thank you. Your proposal got me far enough. It still errored out on some missing dependencies. Onse I added them everything worked. Thanks:


                        <dependency>
                        <groupId>asm</groupId>
                        <artifactId>asm</artifactId>
                        <version>2.2.2</version>
                        </dependency>
                        <dependency>
                        <groupId>asm</groupId>
                        <artifactId>asm-commons</artifactId>
                        <version>2.2.2</version>
                        </dependency>

                        Comment


                        • #13
                          I've run into the same problem as well. Solution with cglib-no dep seems to be just ideal. I can't wait to check it out, as this inner-spring conflict is very annoying.

                          Comment


                          • #14
                            See posting ASM version incompatibilities, using Spring @Autowired with Hibernate related to this thread.

                            If you use maven add this to your pom.xml:

                            Code:
                            <dependency>
                              <groupId>org.hibernate</groupId>
                              <artifactId>hibernate</artifactId>
                              <version>3.2.2.ga</version>
                              <exclusions>
                                <exclusion>
                                  <groupId>asm</groupId>
                                  <artifactId>asm</artifactId>
                                </exclusion>
                                <exclusion>
                                  <groupId>asm</groupId>
                                  <artifactId>asm-attrs</artifactId>
                                </exclusion>
                                <exclusion>
                                  <groupId>cglib</groupId>
                                  <artifactId>cglib</artifactId>
                                </exclusion>
                              </exclusions>
                            </dependency>
                            <dependency>
                              <groupId>asm</groupId>
                              <artifactId>asm</artifactId>
                              <version>2.2.3</version>                       
                            </dependency>
                            <dependency>
                              <groupId>cglib</groupId>
                              <artifactId>cglib-nodep</artifactId>
                              <version>2.1_3</version>
                            </dependency>
                            Now asm-2.2.3 is used and cglib-nodep for hibernate. cglib-nodep uses its own asm classes.

                            Comment

                            Working...
                            X