Hibernate: Commiting MariaDB via JPA -
im trying write small application should offer restful interface. @ it's own works current hibernate-version relatively good.
when trying test, serverside code modifying this:
entitymanager manager = // [...] manager.gettransaction.begin(); aentity entity1 = manager.find(aentity.class, 4711); entity1.setsomething("whatever"); manager.merge(entity1); manager.gettransaction.commit(); manager.close(); normally should work. when testing junit not.
entitymanager manager = // [...] // insert test data response r1 = target(url).request().put(someaentitychangeinfo); assertequals(200, r1.getstatus()); manager.refresh(maentity); assertequals("whatever", maentity.getsomething()); // set , commited on server-side the last assert fails saying maentity (which should updated) contains old data. i'm not sure whether behaviour may race condition, since once (but once) assert okay.
how make sure data got commited before asserting?
using mariadb, mariadb connector/j, hibernate 5.0.7 , jersey 2.22.1.
the issue seems mix of flushing transactions , connection isolation.
to resolve this:
- set flush-mode commit:
manager.setflushmode(flushmodetype.commit); - set connection isolation testing
read_commitedtest-connection able see changes made tested code entitymanager. production higher isolation better. jpa-property:<property name="hibernate.connection.isolation" value="2" />
there hibernate's autocommit property. set false keeping more control behaviour.
Comments
Post a Comment