I have this class TransactionManager:
public class TransactionManager {
private static ThreadLocal<Transaction> currentTransaction;
public static Session getCurrentSession() {
if(currentTransaction == null) {
currentTransaction.set(
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction());
}
return HibernateUtil.getSessionFactory().getCurrentSession();
}
public static void rollback() {
currentTransaction.get().rollback();
HibernateUtil.getSessionFactory().getCurrentSession().close();
currentTransaction = null;
}
public static void beginTransaction() {
currentTransaction.get().begin();
// HibernateUtil.getSessionFactory().getCurrentSession().close();
// currentTransaction = null;
}
public static void commit() {
currentTransaction.get().commit();
HibernateUtil.getSessionFactory().getCurrentSession().close();
currentTransaction = null;
}
}
and the error occurs at beginTransaction(); I've never user a ThreadLocal and I don't really know why I get this error. Without using a ThreadLocal it works fine. The reason I use a ThreadLocal is because I need a different session for every user(I want to create an application like Messenger).
Full error:
java.lang.ClassCastException:
org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction cannot be cast to
com.util.TransactionManager