I'm having an interesting problem show up when I attempt to use my Annotated classes in a deployed web application. Here is the scenario :
<Works>
1 - I deploy my web application (in a .war file). My persistence unit is setup in my persistence.xml file as a JTA datasource. The following two options are also set :
Code:
<property name="hibernate.archive.autodetection" value="class, hbm" />
<property name="hibernate.mapping.precedence" value="hbm" />
Once the app is deployed I can access it correctly and everything runs fine.
<Doesn't Work>
2 - I deploy my web application the same way, only I change the persistence.xml file to use the class files instead of the hbm.xml files :
Code:
<property name="hibernate.mapping.precedence" value="class" />
Once the app is deployed I attempt to access the first page in the application and I get the following error in my appserver log files :
Code:
2007-02-09 11:16:42,817 DEBUG: AnnotationConfiguration: processing manytoone fk mappings^M
2007-02-09 11:16:42,817 DEBUG: AnnotationConfiguration: Found referenceEntityName = us.co.douglas.soso.model.District^M
2007-02-09 11:16:42,817 DEBUG: AnnotationConfiguration: Found classMapping = null^M
2007-02-09 11:16:42,817 ERROR: PersistenceUtil: Error finding or building entityManagerFactory! Cause: ^M
javax.persistence.PersistenceException: java.lang.NullPointerException^M
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:252)^M
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:120)^M
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)^M
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)^M
at us.co.douglas.soso.util.PersistenceUtil.getEntityManagerFactory(PersistenceUtil.java:114)^M
at us.co.douglas.soso.util.PersistenceUtil.getEntityManager(PersistenceUtil.java:240)^M
at us.co.douglas.soso.util.PersistenceUtil.getEntityManager(PersistenceUtil.java:222)^M
at us.co.douglas.soso.filters.HibernateJTAFilter.doFilter(HibernateJTAFilter.java:107)^M
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:210)^M
at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:55)^M
at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:161)^M
at java.security.AccessController.doPrivileged(Native Method)^M
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)^M
at us.co.douglas.soso.filters.JurisdictionFilter.doFilter(JurisdictionFilter.java:228)^M
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:210)^M
at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:55)^M
at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:161)^M
at java.security.AccessController.doPrivileged(Native Method)^M
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)^M
at org.displaytag.filter.ResponseOverrideFilter.doFilter(ResponseOverrideFilter.java:125)^M
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:210)^M
at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:55)^M
at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:161)^M
at java.security.AccessController.doPrivileged(Native Method)^M
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)^M
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:263)^M
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:551)^M
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:225)^M
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:173)^M
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:551)^M
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)^M
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:551)^M
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:132)^M
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:551)^M
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:933)^M
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:185)^M
at com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:653)^M
at com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:534)^M
at com.sun.enterprise.web.connector.grizzly.ProcessorTask.doTask(ProcessorTask.java:403)^M
at com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:55)^M
Caused by: java.lang.NullPointerException^M
at org.hibernate.cfg.AnnotationConfiguration.processFkSecondPassInOrder(AnnotationConfiguration.java:383)^M
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:286)^M
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1115)^M
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1233)^M
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:154)^M
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:869)^M
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:183)^M
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:240)^M
... 39 more
From looking at the code, it would appear that AnnotationConfiguration.getClassMapping() is returning null for the supplied referenceEntityName.
Has anyone seen this issue before? Is it an error in my annotated file? (They were generated by the Hibernate Eclipse plugin) It's odd that the app runs fine when using the hbm.xml files, but fails when trying to use the annotated files. The annotated files were created based on the hbm.xml files (using the Hibernate Eclipse plugin).
Any help would be greatly appreciated. I can attach my persistence.xml and a couple of my annotated classes if needed.
Hibernate version: 3.2.2
Hibernate EntityManager version: 3.2.1-GA
Hibernate Annotations version: 3.2.1-GA
App Server SunOne8