Hi,
I am using Hibernate within a JMS reciever. The code seems to hang when
we make a call to DatabaseUtil.beginTransaction().
I am using HibernateUtil present in caveatemptor-0.9.5 to make the
required database session activities.
I do not get any exception. It just hangs there! Not too sure if it has
anything to do with Threadlocal?
JMS Queue Reciever code:
Code:
... some code here
//When the JMS queue recieves any message ...
public void onMessage(Message msg) {
try {
if (msg instanceof TextMessage) {
System.out.println(((TextMessage) msg).getText());
} else if (msg instanceof ObjectMessage) {
try {
System.out.println("\t[onMessage] (1)");
//Hangs after this
//Calls HibernateUtil.beginTransaction(); shown below
HibernateUtil.beginTransaction();
... code continues here
Code from HibernateUtil.java from caveatemptor-0.9.5
Code:
public static void beginTransaction()
throws Exception {
Transaction tx = (Transaction) threadTransaction.get();
try {
if (tx == null) {
//Hangs here .....
tx = getSession().beginTransaction();
threadTransaction.set(tx);
}
} catch (HibernateException ex) {
throw new Exception(ex);
}
}
But a simple code like this works !
Code:
MyBean MyBeanObj = new MyBean();
HibernateUtil.beginTransaction();
HibernateUtil.getSession().saveOrUpdate(MyBeanObj);
HibernateUtil.commitTransaction();
I am lost here, can someone guide me?