| Hi.
 I recently migrated an API service of mine from Hibernate 3.6.7 to Hibernate 4.1.7.
 Now, I get the following exception very frequently
 org.hibernate.TransactionException: nested transactions not supported
 at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.begin(AbstractTransactionImpl.java:152)
 at org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1392)
 
 The exception happens randomly on some APIs but doesn't get reproduced every time. The exception is intermittent.
 
 I made sure to use one single transaction for a function and not creating a nested transaction anywhere in my code. Following is a sample code snippet where the exception happens sometimes :
 
 @Override
 public ApiResponse<BaseModel> getLanguages() {
 List<BaseModel> result = null;
 Integer total;
 Transaction trans = null;
 try {
 trans = dictionaryDao.beginTransaction();
 total = dictionaryDao.getLanguagesCount().intValue();
 List<LanguageMaster> languageDOList = dictionaryDao.getLanguages();
 result = new ArrayList<BaseModel>();
 result = format(languageDOList);
 trans.commit();
 } catch (RuntimeException e) {
 if (trans != null)
 trans.rollback();
 throw e;
 }
 return getResponse(result);
 }
 
 The function dictionaryDao.begintransaction is defined as below :
 
 public Transaction beginTransaction() {
 getCurrentSession().setFlushMode(FlushMode.COMMIT);
 Transaction t = getCurrentSession().beginTransaction();
 return t;
 }
 
 The exception occurs while beginning the transaction in dictionaryDao.begintransaction at  Transaction t = getCurrentSession().beginTransaction();.
 
 We are using BoneCP as the connection pool provider.
 
 Can someone provide any help on how to get around this random error ?
 
 Thanks,
 Rajat
 
 
 |