java - HIbernate: "Nested Transactions not supported" when all transactions properly committed -


i have read few posts on topic: e.g., here , here

in case, transactions committed , exceptions handled rollback.

currently, building model layer web app (spring/hibernate/postgres). using junit rigorously test build. reason, on 1 delete test repeatedly got "nested transaction not supported" exception.

session session=hibernatedao.getsessionfactory().getcurrentsession();      try     {             session.gettransaction().begin();          list<testunittype> result = session.createquery("from testunittype").list();            testunittype itemtodelete = result.get(0);           session.delete(itemtodelete);         session.gettransaction().commit();      } catch (exception e)     {         testss.getlogger().error(e.tostring(), e);          session.gettransaction().rollback();         fail(e.tostring());     } 

the exception thrown when calling transaction prior query. previous method closed transaction couched in same syntax method (and debugged).

i resolved issue creating kludge method , using session:

public static session resetcurrentsession() {     session oldsession = getsessionfactory().getcurrentsession();     if(oldsession.isopen())     {         oldsession.close();     }     return getsessionfactory().getcurrentsession(); } 

all unit tests run , pass, data in database clean , see no side effects of kludge. nonetheless, uncomfortable using workaround in unit tests. no fix safe if programmer not know cause of problem behind it.

can advise on possible cause of exception?

the answer junit related, not hibernate related.

it seems assert statements in junit exit method, if assert statement prior commit, commit not happen.

this no doubt beginner error in junit, may of use other beginners.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -