For the last year or so, I’ve been working on a project using JBoss and EJB 3.0. As this is a first, no wonder there were some technical difficulties along the way. This post is the first in a series describing the problems we had, and how we overcame them.
The original task was very simple: Let’s create a small application, demonstrating the usage of all the technologies, and start grow our application from there. Starting with running the tutorials coming with the JBoss EJB3 distribution we saw this problem:
--- MBeans waiting for other MBeans --- ObjectName: persistence.units:jar=tutorial.jar,unitName=tempdb State: FAILED Reason: java.lang.RuntimeException: java.lang.NoClassDefFoundError: org/hibernate/MappingNotFoundException I Depend On: jboss.jca:service=DataSourceBinding,name=DefaultDS Depends On Me: jboss.j2ee:jar=tutorial.jar,name=ShoppingCartBean,service=EJB3ObjectName: jboss.j2ee:jar=tutorial.jar,name=ShoppingCartBean,service=EJB3 State: NOTYETINSTALLED I Depend On: persistence.units:jar=tutorial.jar,unitName=tempdb --- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM --- ObjectName: persistence.units:jar=tutorial.jar,unitName=tempdb State: FAILED Reason: java.lang.RuntimeException: java.lang.NoClassDefFoundError: org/hibernate/MappingNotFoundException I Depend On: jboss.jca:service=DataSourceBinding,name=DefaultDS Depends On Me: jboss.j2ee:jar=tutorial.jar,name=ShoppingCartBean,service=EJB3
This was really puzzling. How can JBoss wants us to deploy a small persistence jar, when it can’t satisfy it’s dependencies? Like in most of these cases, it appeared it was another case of DLL hell. The short solution, for JBossAS 4.0.4GA, is as follows: update the modification time of the files (I did it using “touch”, via cygwin), and then run the at install file of the EJB3 package. I might warn you in advance that the rest of this post is full with all the nagging version differences that gave DLL hell its name…
After searching the hibernate API and subversion repository, I’ve found that the relevant class (org.hibernate.MappingNotFoundException) was added to Hibernate in version 3.2.0.cr3 or 3.2.0.cr4. The version that comes with the EJB3 RC9 is cr4. The version I had in the JBossAS (4.0.4GA) is cr2, which lacked that file.
The EJB3 ant installer should have copied the new version to the JBossAS, but unfortunately the modification time of the JBossAS jars was newer than the EJB3, so ant has ignored the copy request.
So this is how the solution works – using “touch” updates the modification time of the EJB3 jars. This makes them newer than those th JBossAS has and then they were copied correctly.
By the way, if you are using JBossAS 4.0.5, you probably don’t want to do this, but rather keep the original Hibernate jars that came with the JBoss. The reason is that JBossAs 4.0.5 contains the final version of Hibernate (3.2.0.ga), which is newer than the one bundled in the EJB3.