-
1. Re: Hibernate In Action/HibernateUtil/JBoss4+Hibernate3 Prob
garbett May 20, 2005 11:57 AM (in response to garbett)Link to bug report got truncated, here's the actual link:
http://jira.jboss.com/jira/browse/JBAS-1828
Sorry about that -
2. Re: Hibernate In Action/HibernateUtil/JBoss4+Hibernate3 Prob
garbett May 20, 2005 2:37 PM (in response to garbett)I've been playing with it today, and the best solution seems to be to not use HibernateUtil. The reason it was created was to solve many of the problems that are taken care of by org.jboss.hibernate.session.HibernateContext. Usage of HibernateContext results in less code. The same amount in the code using Hibernate, minus the whole HibernateUtil class.
Highly recommended reading has been provided by JBoss already: http://wiki.jboss.org/wiki/Wiki.jsp?page=JBossHibernate2
The upshot of this is to just be sure to call session.flush(); before closing the session.
When using HibernateContext is closing the session even necessary? -
3. Re: Hibernate In Action/HibernateUtil/JBoss4+Hibernate3 Prob
fmaredia May 23, 2005 12:36 AM (in response to garbett)Any examples. Can someone provide any class similar to HibernateUtil?
-
4. Re: Hibernate In Action/HibernateUtil/JBoss4+Hibernate3 Prob
jukvaa May 23, 2005 5:31 AM (in response to garbett)Hello,
In Hibernate3 I think that you should use SessionFactory.getCurrentSession() instead of HibernateContext. I think that will do the same thing in application server independent way.
But the problem that I see here is that neither of these will work if you are not inside a transaction. And I would like to keep the code similar whether I'm inside transaction or not. And it feels unnecessary overhead to have transaction in every select method.
One solution that came to my mind is that create a HibernateUtil that uses SessionFactory.getCurrentSession(), traps exception that happens if transaction is not running, and then creates and returns ThreadLocal session instead.
The closeSession() method would have to close the session if it is ThreadLocal session and do nothing if it's Transaction related session. Don't know would this work, but I'm going to try...