Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
3.0
Mapping documents:
These are fine
Code between sessionFactory.openSession() and session.close():
example of one method:
public Role findRole(String role)
{
Session session = HibernateUtil.getSession();
Transaction tx = null;
AnalystDAO anDAO = new AnalystDAO();
Roles retRole = new Roles();
try
{
session.beginTransaction();
retRole = anDA).getRole(session, role);
tx.commit();
session.close();
return retRole;
}
catch (HibernateExeption ex)
{
if (tx != null)
{
tx.rollback();
}
ex.printStackTrace();
}
catch (InfrastructureException ex)
{
if (tx != null)
{
tx.rollback();
}
throw new InfrastructureException(ex);
}
finally
{
session.close();
}
return retRole;
}
HibernateUtil:
public class HibernateUtil
{
private static final SessionFactory sessionFactory;
static
{
try
{
sessionFactory newConfiguration().configure().buildSessionFactory();
}
catch(Throwable ex)
{
ex.printStackTrace();
throw new ExceptionInInitializer(ex);
}
}
public static Session getSession()
{
Session session = null;
try
{
session = sessionFactory.getCurrentSession();
if (session == null)
{
session = sessionFactory.openSession();
}
}
catch (HibernateException ex)
{
ex.printStackTrace();
}
catch (NullPointerException ex)
{
session = sessionFactory.openSession();
}
return session;
}
}
hibernate.cfg.xml:
<session-factory name="java:hibernate/SessionFactory">
<property name="hibernate.connection.datasource">java:SybaseDS</property>
<property name="jta.UserTransaction">java:comp/UserTransaction</property>
<property name="hibernate.dialect">org.hibernate.dialect.SybaseDialect</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory </property>
<property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
MAPPING FILES
hibernate-service.xml:
<server>
<mbean code="org.hibernate.jmx.Hibernate" name="jboss.har:service=Hibernate">
<attribute name="DatasourceName">java:/SybaseDS</attribute>
<attribute name="Dialect">org.hibernate.dialect.SybaseDialect</attribute>
<attribute name="SessionFactoryName">java:/hibernate/SessionFactory</attribute>
<attribute name="CacheProviderClass">org.hibernate.cahce.EhCacheProvider</attribute>
<attribute name="ShowSqlEnabled">true</attribute>
</mbean>
</server>
Full stack trace of any exception that occurs:
There is not one to print but we seem to run fine for hours then things start going haywire. A number of connections are being left hanging open on the dbServer even though it seems that we are closing everything. We end up with a JTAException.
Name and version of the database you are using:
Sybase ASE 12.5.2
Debug level Hibernate log excerpt:
Debug
the call in HibernateUtil to getCurrentSession never succeeds so we are always calling openSession. We are always throwing a nullpointerexception and then make the call to openSession. I believe the root of my problem has to be that the JTATransaction stuff is not setup correctly so that is not being used. I am NOT using EJB but just java and DAO pattern.
I want to the jboss container to handle all of the open, close, flush commit and rollbacks but it is not working. I am desperate at this point and can't get this figured out. Is there somewhere specific that I need to configure JTA within JBoss? I didn't find anywhere myself.