Hello,
I am trying to set up a simple Hibernate (with annotations) project with JBoss and Maven 2.
I have put all my hibernate-classes inside a sub-project that is packaged up into a .HAR file and deployed in the main .EAR file. The structure of the .HAR file is:
Code:
bm-hibernate.har/META-INF/jboss-service.xml
bm-hibernate.har/META-INF/MANIFEST.MF
bm-hibernate.har/com.path.to/HibernateObject
I then have a HibernateUtil class that I use to get the Hibernate Session:
Code:
package ...;
import javax.naming.InitialContext;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
public class HibernateUtil {
private static SessionFactory sessionFactory;
static {
try {
InitialContext ictx = new InitialContext();
sessionFactory = (SessionFactory)ictx.lookup("java:/hibernate/SessionFactory");
sessionFactory.openSession();
} catch (Throwable ex) {
System.out.println("EXCEPTION: " + ex);
ex.printStackTrace();
throw new ExceptionInInitializerError(ex);
}
}
public static Session getSession() throws HibernateException {
return sessionFactory.openSession();
}
}
However, when I try to run sessionFactory.openSession I get the following error:
Code:
14:11:44,562 WARN [SessionFactoryObjectFactory] Not found: 2c99e4e110019b42011001d5f1690008
14:11:44,563 INFO [STDOUT] EXCEPTION: java.lang.NullPointerException
14:11:44,563 ERROR [STDERR] java.lang.NullPointerException
at com.path.to.source.hibernate.util.HibernateUtil.<clinit>(HibernateUtil.java:22)
When the application is deployed to JBoss, it does state this though:
Code:
14:11:42,698 INFO [Hibernate] SessionFactory successfully built and bound into JNDI [java:/hibernate/SessionFactory]
My jboss-service.xml file looks like this:
<server>
<mbean code="org.jboss.hibernate.jmx.Hibernate" name="jboss.har:service=Hibernate">
<attribute name="DatasourceName">java:/MyDataSourceDS</attribute>
<attribute name="Dialect">org.hibernate.dialect.OracleDialect</attribute>
<attribute name="SessionFactoryName">java:/hibernate/SessionFactory</attribute>
<attribute name="CacheProviderClass">org.hibernate.cache.HashtableCacheProvider</attribute>
<attribute name="ShowSqlEnabled">true</attribute>
<attribute name="ScanForMappingsEnabled">true</attribute>
</mbean>
</server>