Announcement Announcement Module
Collapse
No announcement yet.
org.objectweb.asm.ClassVisitor different in spring and hibernate Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • org.objectweb.asm.ClassVisitor different in spring and hibernate

    When using both spring and hibernate, I ran into some rather difficult to debug problems caused by each product using different versions of the same class files. Since the first class file loaded prevents another class file of the same type being loaded, this led to unpredictable behavior. In particular, I would have it running fine from my IDE, but not from ant. When I finally got it running from ant, it stopped working in the IDE. On the theory that the order in which the jar files were loaded was the difference between ant and my IDE, I wrote a program to scan all the class files in all the jars, and tell me which classes conflicted.

    The class in particular that was causing me grief was org.objectweb.asm.ClassVisitor. In spring, this was in lib/asm/asm-2.2.2.jar, in hibernate, this was in lib/asm.jar. Simply deleting asm-2.2.2.jar fixed my problem, but it got me thinking that my fix was more luck than a reliable solution. By deleting the spring version to get hibernate working, I risk breaking spring.

    Does anyone know of any work/research related to solving the problem where two separate libraries depend on two different versions of the same class file? Seems like a difficult problem that is inevitable when using many open source libraries. It would be nice if I could get the spring methods to call the spring version and the hibernate methods to call the hibernate version, but the JVM is just not built this way.

    Spring version: 2.0-rc3
    Hibernate version: 3.2.0.cr2

    Sean Shubin

  • #2
    In general you should not have two versions of the same jar file loaded by the same class loader - it's asking for trouble. But class loaders being what they are, you are stuck with having to decide which one to use. The alternative of having Spring and Hibernate loaded by different class loaders is probably not one that you can really consider practical, but that is the only way to use both versions in the same VM.

    The most recent is almost certainly the Spring dependency. I think you just have to take the most recent asm version and hope that it works with both tools, or else see if you can downgrade Spring to a version that matches. Unfortunately there is very little else you can do, and I doubt if you find an official statement from hibernate (or cglib, which is actually the dependency in question), saying that the more recent version categorically will or will not work.

    Comment


    • #3
      One simple workaround is to use cglib_nodep which already contains the ASM classes required but with a different package name so using a different version of ASM if possible, AFAIK.

      Comment

      Working...
      X