• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Intermitent nested transaction exception when using hibernate 4.1.3

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am getting a intermitent nested transaction exception when using hibernate 4.1.3. The error is as follows:

org.hibernate.TransactionException: nested transactions not supported
org.hibernate.engine.transaction.spi.AbstractTransactionImpl.begin(AbstractTransactionImpl.java:152)
org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1396)
sun.reflect.GeneratedMethodAccessor39.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:616)
org.hibernate.context.internal.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:352)
$Proxy63.beginTransaction(Unknown Source)
com.tcs.cto.enable.first.dao.UniversalDao.retrieveByFieldValue(UniversalDao.java:41)
com.tcs.cto.enable.first.dao.UniversalDao.lookup(UniversalDao.java:62)
com.tcs.cto.enable.first.application.EquityInstrumentInformationFactory.createEquityInstrumentInformation(EquityInstrumentInformationFactory.java:32)
com.tcs.cto.enable.first.application.EquityInstrumentInformationFactory.getEquityInstrument(EquityInstrumentInformationFactory.java:27)
com.tcs.cto.enable.first.ipad.ws.organizationdetails.OrganizationDetailsFactory.createOrganizationDetails(OrganizationDetailsFactory.java:25)
com.tcs.cto.enable.first.ipad.ws.organizationdetails.OrganizationDetailsResource.getOrganizationDetails(OrganizationDetailsResource.java:29)
sun.reflect.GeneratedMethodAccessor49.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:616)
com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)
com.sun.jersey.server.impl.uri.rules.SubLocatorRule.accept(SubLocatorRule.java:134)
com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469)
com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400)
com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:708)



The problem is I have no nested exception. The exception is thrown once / twice everyday. My universal DAO class looks like this.

public class UniversalDao {

public void update(Object object){
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
session.saveOrUpdate(object);
session.getTransaction().commit();
}

public void add(Object object){
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
session.save(object);
session.getTransaction().commit();
}

@SuppressWarnings("unchecked")
public List<Object> retrieveAllObjects(String objectName) {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Query query = session.createQuery("from "+ objectName);
List<Object> objectList = (List<Object>) query.list();
session.getTransaction().commit();
return objectList;
}

@SuppressWarnings("all")
public List retrieveByFieldValue(Class classObject, String propertyName, String propertyValue){
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Criteria criteria = session.createCriteria(classObject);
criteria.add(Restrictions.eq(propertyName, propertyValue));
List list = criteria.list();
session.getTransaction().commit();
return list;
}

@SuppressWarnings("all")
public List retrieveByFieldValue(Class classObject, String propertyName, Object propertyValue){
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Criteria criteria = session.createCriteria(classObject);
criteria.add(Restrictions.eq(propertyName, propertyValue));
List list = criteria.list();
session.getTransaction().commit();
return list;
}

@SuppressWarnings("all")
public Object lookup(Class classObject, String propertyName, String propertyValue){
List list = retrieveByFieldValue(classObject,propertyName,propertyValue);
Object obj = ( list != null && list.size() > 0 ) ? list.get(0) : null;
return obj;
}

@SuppressWarnings("all")
public Object lookup(Class classObject, String propertyName, Object propertyValue){
List list = retrieveByFieldValue(classObject,propertyName,propertyValue);
Object obj = ( list != null && list.size() > 0 ) ? list.get(0) : null;
return obj;
}

@SuppressWarnings("all")
public void delete(Object object){
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
session.delete(object);
session.getTransaction().commit();
}

public void deleteAll(String objectName){
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Query query = session.createQuery("delete "+ objectName);
query.executeUpdate();
session.getTransaction().commit();
}

@SuppressWarnings("all")
public List retrieveMax(Class classObject, String propertyName){
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Criteria criteria = session.createCriteria(classObject);
criteria.setProjection(Projections.max(propertyName));
List list = criteria.list();
session.getTransaction().commit();
return list;
}

Please help


 
You may have just won ten million dollars! Or, maybe a tiny ad.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic