Greetings, actually what's my problem. I can not adequately get Hibernate to work. Maybe someone can tell a recipe for approaching it, I don’t ask for the code, just what, how to set it up so as not to catch all sorts of problems.

What I have:

Entities with connections. fetch everywhere LAZY, cascade = ALL

A couple of methods implemented in the style of open session, save / receive, commit. Next session takes my bike, which closes them after 10 seconds.

Tests that in parallel begin to peel at all DAO methods,

From time to time, these tests get:

LockAcquisitionException: could not execute statement

LockAcquisitionException: could not extract ResultSet

and their source HsqlException: transaction rollback: serialization failure

Everything is so bad that I already screwed it in

<property name="jta.UserTransaction">8</property> <property name="hibernate.connection.isolation">8</property> hsqldb.tx=mvcc 

and hell, I think he ignores them. Or I do not understand why at the SERIALIZATION level can it catch problems with transactions?

If necessary, I can throw off the code. Although I'm just asking about the approach :)

  • one
    Probably transactions are in conflict. Trying to simultaneously change some records. Or one changes, and the other at this time trying to read them. But because of locks and high levels of isolation, a conflict arises. The second transaction database writes out figvam. The serializable level is not supported by all databases in an honest way. In fact, their transactions do not wait for each other, but are always executed in parallel. Only one succeeds; the others are rejected when trying to complete. The main thing is to ensure the condition of the absence / presence of any phenomena upon successful completion. - Sergey
  • I recommend that you run tracer on a database in order to catch events that occur during the active operation of your application. An example tracer for microsoft sql server is the profiler. If you have another DBMS, then use another one. Then you clearly see what Hibernate does in your database. - Mikhail Grebenev
  • one
    Plus, there are errors when open transactions remain when using an explicit transactional mode of operation. In this case, you may actually have conflicts with several open transactions. Read about org.hibernate.Session.beginTransaction () and org.hibernate.Transaction.commit (). You can also check open Session and Transaction transactions: if (session! = Null && session.isOpen ()) {session.close (); } and if (currentTransaction! = null && currentTransaction.isActive ()) {currentTransaction.commit (); } - Mikhail Grebenev
  • And what to read about beginTransaction and commit? JavaDoc saw them, thought enough) For HSQLDB I did not find a tracer. - LeshaFloy
  • Comments about locks in the database caught up with the idea. Forced from HSQLDB forcedly hsqldb.tx_level = read_commited rearranged isolation in 4 (REPEATABLE_READ) And about a miracle, this combination of 30 test runs never failed. But here is the question, in the database is read_commited, in the REPEATABLE_READ hibernate. And so it works, but not otherwise. What kind of anomaly is this? Is it legal? Or have I built a UFO there? - LeshaFloy

0