After migrating our v3.6 application to the 4.0.0 release, one of the first problems we ran into was a NullPointerException when attempting to create a new session. I hope this helps out others that might run into similar problems:
Code:
2011-12-15 21:55:16 ERROR c.a.f.ListingTools main - Got exception:
java.lang.NullPointerException: null
at java.lang.Class.forName0(Native Method) ~[na:1.6.0_27]
at java.lang.Class.forName(Class.java:247) ~[na:1.6.0_27]
at org.hibernate.annotations.common.util.ReflectHelper.classForName(ReflectHelper.java:143) ~[hibernate-commons-annotations.jar:4.0.1.Final]
at org.hibernate.annotations.common.reflection.java.JavaReflectionManager.classForName(JavaReflectionManager.java:117) ~[hibernate-commons-annotations.jar:4.0.1.Final]
at org.hibernate.envers.configuration.RevisionInfoConfiguration.configure(RevisionInfoConfiguration.java:256) ~[hibernate-envers.jar:4.0.0.Final]
at org.hibernate.envers.configuration.AuditConfiguration.<init>(AuditConfiguration.java:95) ~[hibernate-envers.jar:4.0.0.Final]
at org.hibernate.envers.configuration.AuditConfiguration.getFor(AuditConfiguration.java:135) ~[hibernate-envers.jar:4.0.0.Final]
at org.hibernate.envers.event.EnversIntegrator.integrate(EnversIntegrator.java:63) ~[hibernate-envers.jar:4.0.0.Final]
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:295) ~[hibernate-core.jar:4.0.0.Final]
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1737) ~[hibernate-core.jar:4.0.0.Final]
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1775) ~[hibernate-core.jar:4.0.0.Final]
at com.altosresearch.utils.DBUtils.createSession(DBUtils.java:86) ~[classes/:na]
After a few hours of source-level debugging, the problem came down to one entity mapping file (.hbm.xml) that had been working nicely under v3.6 but not under v4.0.0.
The <class> definition that was causing the problem:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
<class entity-name="com.altosresearch.model.reporting.CityZipSearchResult">
...
</class>
</hibernate-mapping>
The problem was the use of 'entity-name' instead of 'name'. The fix looked like this:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
<class entity-name="com.altosresearch.model.reporting.CityZipSearchResult"
name="com.altosresearch.model.reporting.CityZipSearchResult">
</class>
</hibernate-mapping>