-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Could not register synchronization for container transaction
PostPosted: Thu Mar 22, 2007 1:09 pm 
Newbie

Joined: Tue Feb 07, 2006 1:32 pm
Posts: 7
Location: Toronto, Ontario
Hi,

I am using hibernate 3.0 and if I use a transaction I get the following exception:

org.hibernate.TransactionException: Could not register synchronization for container transaction
at org.hibernate.transaction.CMTTransaction.begin(CMTTransaction.java:42)
at org.hibernate.transaction.CMTTransactionFactory.beginTransaction(CMTTransactionFactory.java:22)
at org.hibernate.jdbc.JDBCContext.beginTransaction(JDBCContext.java:212)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1015)
at com.intria.bip.pendingitems.dao.PendingItemsDAO.purgePendingItemsDaily(PendingItemsDAO.java:403)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:248)
at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:165)
at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:66)
at org.quartz.core.JobRunShell.run(JobRunShell.java:195)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:520)
22/Mar/2007 12:00:00.140 INFO Transaction "" - [org.quartz.core.JobRunShell] Job DEFAULT.purgePendingItemsJobDetail threw a JobExecutionException:
org.quartz.JobExecutionException: Could not invoke method 'purgePendingItemsDaily' on target object [com.intria.bip.pendingitems.dao.PendingItemsDAO@7ccb74] [See nested exception: org.hibernate.TransactionException: Could not register synchronization for container transaction]
at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:174)
at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:66)
at org.quartz.core.JobRunShell.run(JobRunShell.java:195)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:520)
* Nested Exception (Underlying Cause) ---------------
org.hibernate.TransactionException: Could not register synchronization for container transaction
at org.hibernate.transaction.CMTTransaction.begin(CMTTransaction.java:42)
at org.hibernate.transaction.CMTTransactionFactory.beginTransaction(CMTTransactionFactory.java:22)
at org.hibernate.jdbc.JDBCContext.beginTransaction(JDBCContext.java:212)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1015)
at com.intria.bip.pendingitems.dao.PendingItemsDAO.purgePendingItemsDaily(PendingItemsDAO.java:403)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:248)
at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:165)
at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:66)
at org.quartz.core.JobRunShell.run(JobRunShell.java:195)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:520)

This is the code between opening and closing the session:

try {
session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
/* 1.Retrieve all records having status=In Progress, Items Retrieved, Items Retrieval Failed
*AND SYSDATE - UPDATEDTS > 24 hours
*and for each such record insert a record in the GDP_Audit with transactionstatus=TIMEOUT
* 2.Delete the records in the Pending Items table based on the specified criteria:
* - all records having the following statuses:
* NotificationForFailure Queue Fail, NotificationForFailure Sent,
* NotificationForFailure Fail, NotificationForSuccess Fail,
* NotificationForSuccess Queue Fail, Items Received
* OR
*- status=In Progress, Items Retrieved, Items Retrieval Failed, NotificationForSuccess Sent
*AND SYSDATE - UPDATEDTS > 24 hours
*/
//List pendingItems = sess.createQuery(buildPurgeSQL()).list();
//Query q = sess.createQuery(buildPurgeSQL());

List statusesWithCondition = new ArrayList();
List statusesWithoutCondition = new ArrayList();
statusesWithoutCondition.add(I3PendingItemsStorage.STATUS_NOTIFICATION4FAILURE_SENT);
statusesWithoutCondition.add(I3PendingItemsStorage.STATUS_NOTIFICATION4SUCCESS_FAIL);
statusesWithoutCondition.add(I3PendingItemsStorage.STATUS_NOTIFICATION4FAILURE_FAIL);
statusesWithoutCondition.add(I3PendingItemsStorage.STATUS_NOTIFICATION4SUCCSSS_QUEUE_FAIL);
statusesWithoutCondition.add(I3PendingItemsStorage.STATUS_NOTIFICATION4FAILURE_QUEUE_FAIL);
statusesWithoutCondition.add(I3PendingItemsStorage.STATUS_ITEMS_RECEIVED);

statusesWithCondition.add(I3PendingItemsStorage.STATUS_IN_PROGRESS);
statusesWithCondition.add(I3PendingItemsStorage.STATUS_ITEMS_RETRIEVED);
statusesWithCondition.add(I3PendingItemsStorage.STATUS_ITEMS_RETRIEVAL_FAILED);
statusesWithCondition.add(I3PendingItemsStorage.STATUS_NOTIFICATION4SUCCESS_SENT);

Criteria criteria = session.createCriteria(PendingItemRecordImpl.class);
criteria.setCacheMode(CacheMode.REFRESH);
criteria.setCacheRegion(this.entity);
criteria.setLockMode(LockMode.UPGRADE);
criteria.add(Expression.or(
Expression.in("status", statusesWithoutCondition),
Expression.and(
Expression.in("status", statusesWithCondition),
Expression.le("updatedTs", getBackInTime(DAYS_TO_PURGE_AFTER))
)
));

List pendingItems = criteria.list();
logger.debug("***** We got ***** "+pendingItems.size()+" items to delete");
Iterator it = pendingItems.iterator();
while(it.hasNext()) {
PendingItemRecordImpl curentPendingRecord = (PendingItemRecordImpl)it.next();
String transactionId = curentPendingRecord.getId();
session.delete(curentPendingRecord);

if (compareStatusWithStatusesInlist(curentPendingRecord.getStatus(), statusesWithCondition)) {
auditLogger.logBIPTransactionTimedOut(getRequestMap(transactionId, getActionTypeFromAuditTable(curentPendingRecord.getId())), getResponseMap(transactionId));
}
}
tx.commit();
//session.flush();
} catch (HibernateException e) {
logger.error(">>>>>>>>>>>>>>>>>>>>>>>>>>Hibernate Exception");
e.printStackTrace();
throw e;
}
finally {
if (null != session) {
session.close();
}
logger.logMethodEnd("Daily purge of the Pending Items tables");
}

Basically when I use exactly the same code in a non-managed environment (just getting a connection using an Oracle driver) everything works fine. I get the exception in a managed environment (Weblogic).
The database is Oracle 9.2.0.1.
Hibernate log is in DEBUG mode.
Could you please help me to identify the issue?
Thank you.


Top
 Profile  
 
 Post subject: I found the issue
PostPosted: Wed Mar 28, 2007 10:25 am 
Newbie

Joined: Tue Feb 07, 2006 1:32 pm
Posts: 7
Location: Toronto, Ontario
After a long search I found the issue:
In the cfg.xml file I was using CMTTransactionFactory.

CMTTransactionFactory always assumes that the container has started a JTA transaction. This will be true if you use the your own EJBs that use container managed transaction. In my case this was not true so I changed this configuration to use the JTATransactionFactory. When JTATransactionFactory is configured, Hibenate will use the JTA transaction if it already exists, but will start a JTA transaction if it does not.

So instead of:
<property name="transaction.factory_class">
org.hibernate.transaction.CMTTransactionFactory
</property>

use:
<property name="transaction.factory_class">
org.hibernate.transaction.JTATransactionFactory
</property>

Cris


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.