These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: v4.0.0 - NullPointerException Class.forName - Solution
PostPosted: Fri Dec 16, 2011 8:42 pm 
Newbie

Joined: Thu May 08, 2008 3:11 pm
Posts: 6
Location: Mountain View, CA
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>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.