java - Hibernate TransactionException: nested transactions not supported -
i getting following exception:
2015-06-23 12:34:30.015 error findrequest:224 - failed org.hibernate.transactionexception: nested transactions not supported @ org.hibernate.engine.transaction.spi.abstracttransactionimpl.begin(abstracttransactionimpl.java:154) @ org.hibernate.internal.sessionimpl.begintransaction(sessionimpl.java:1435) @ sun.reflect.generatedmethodaccessor127.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:606) @ org.hibernate.context.internal.threadlocalsessioncontext$transactionprotectionwrapper.invoke(threadlocalsessioncontext.java:356) @ com.sun.proxy.$proxy5.begintransaction(unknown source)
the method showing exception is:
public list findrequest() { try { transaction trans=sessionfactory.getcurrentsession().begintransaction(); query q = sessionfactory.getcurrentsession().createquery("query"); q.setstring("reqstatus", reqstatus); list result = q.list(); trans.commit(); return result; } catch (runtimeexception re) { logger.error("get failed", re); } return null; }
i getting issue while load testing. added functionality number of web service calls increases. created 1 maintenance thread continue call db. point number of db calls increases 20 times.
i using postgresql. hibernate setting:
<property name="hibernate.bytecode.use_reflection_optimizer">false</property> <property name="hibernate.connection.driver_class">org.postgresql.driver</property> <property name="hibernate.connection.password">******</property> <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/******</property> <property name="hibernate.connection.username">******</property> <property name="hibernate.default_schema">******</property> <property name="hibernate.dialect">org.hibernate.dialect.postgresqldialect</property> <property name="hibernate.search.autoregister_listeners">false</property> <property name="hibernate.show_sql">false</property> <property name="hibernate.current_session_context_class">thread</property> <property name="hibernate.enable_lazy_load_no_trans">true</property>
as can see hibernate setting using default hibernate connection pool. possible connection full , because of transition not released or closed. not using rollback mechanism. hibernate.current_session_context_class=thread, every rest call creating new thread. , method showing exception first 1 called rest api. 1 thread how can throw nested exception. in advance.
this issue may arise if previous transaction has not been rolled back. now, should restart server (glassfish or whatever else use) , try again.
to avoid in future, may want manually roll in catch block:
catch (runtimeexception re) { trans.rollback(); logger.error("get failed", re); }
Comments
Post a Comment