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.
|