Ok I've tried a million things to getCurrentSession, and still cannot seem to get it to work.
I am using JBoss 4.02 and Hibernate3.
Here is the exception:
Code:
java.lang.NullPointerException
at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:509)
at com.atwcorp.trustedapp.domain.util.HibernateUtil.getSession(HibernateUtil.java:150)
Here is my hibernate-service.xml:
Code:
<server>
<mbean code="org.jboss.hibernate.jmx.Hibernate" name="jboss.har:service=Hibernate">
<attribute name="DatasourceName">java:/MyAPP</attribute>
<attribute name="SessionFactoryName">java:/hibernate/SessionFactory</attribute>
<attribute name="Dialect">org.hibernate.dialect.PostgreSQLDialect</attribute>
<attribute name="ShowSqlEnabled">true</attribute>
<attribute name="Hbm2ddlAuto">create-drop</attribute>
</mbean>
</server>
Here is the code to get the session which I put in my HibernateUtil class:
Code:
public static Session getSession {
SessionFactory sessions = null;
try {
Context ctx = new InitialContext();
String jndiName = "java:hibernate/SessionFactory";
sessions = (SessionFactory)ctx.lookup(jndiName);
} catch (NamingException ex) {
//throw new HibernateException(ex);
}
return sessions.getCurrentSession();
}
What am I doing wrong? Thanks in advance