Hibernate version: Hibernate3
My Requirement:
I need to query a table and look for entries that are greater than 90 days old and delete them.
So, I'm trying to use session.connection() and call an oracle specific sql statement to achieve this. The table has a create_date column which I use to derive the number of days. Now when this logic gets invoked I receive a "TransactionException" stating "Could not register synchronization", please, see entire stack trace below. Any feedback is much appreciated.
Code between sessionFactory.openSession() and session.close():
public void deleteExpiredToken()
{
Session hibernateSession = null;
Transaction tx = null;
Connection connection= null;
try
{
hibernateSession = getSessionFactory().getCurrentSession();
tx = hibernateSession.beginTransaction();
connection = hibernateSession.connection();
tx.begin();
hibernateSession.connection().createStatement().executeUpdate("delete token_table where floor(SYSDATE-creation_date) > 90");
tx.commit();
hibernateSession.flush();
hibernateSession.close();
} catch....
Full stack trace of any exception that occurs:
org.hibernate.TransactionException: Could not register synchronization
at org.hibernate.transaction.CMTTransaction.registerSynchronization(CMTTransaction.java:159)
at org.hibernate.context.ThreadLocalSessionContext.currentSession(ThreadLocalSessionContext.java:78)
at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:507)
at com.symantec.portal.am.security.dao.TokenDao.deleteExpiredToken(TokenDao.java:88)
at com.symantec.portal.am.batch.CleanUpExpiredTokenTask.run(CleanUpExpiredTokenTask.java:46)
at java.util.TimerThread.mainLoop(Timer.java:447)
at java.util.TimerThread.run(Timer.java:397)
Caused by: java.lang.NullPointerException
at org.hibernate.transaction.CMTTransaction.registerSynchronization(CMTTransaction.java:156)
... 6 more
Name and version of the database you are using:
Oracle 9i
|