Previusly at JIRA:
Jose Peleteiro:
Automatic dirty checking is a nice features, but at the old-fashioned design (dao.new(), dao.save()) it's not nice.
It may be possible to turn it off at configuration file.
Christian Bauer:
Use a stateless session, read the documentation.
Jose Peleteiro:
StatelessSession does not solve that problem since cache, cascade, event-model, listener, lazy-load... will not work as well.
What I am asking is a way to just turn off automatic dirty checking and continue to use all those features. Is it that bad?
How can I do this (bellow) with automatic dirty, without my client knows that he is using HB, and with lazy-load, cache and etc?
SomeEntity e1 = dao.findById(1);
SomeEntity e2 = dao.findById(1);
e1.setXYZ(123);
e2.setXYZ(123);
if (validation(e1)) dao.save(e1);
if (validation(e2)) dao.save(e1);
Okay, I could do it in a different way, but it is a legancy code and I wish to use Hibernate.
I can understand you all love dirty check (I think its cool as well, but not at every design) and have no focus on it, but if I submit a patch on it, is it welcome?
---------------------------------------------------------------
From StatelessSession JavaDoc:
A command-oriented API for performing bulk operations against a database.
A stateless session does not implement a first-level cache nor interact with any second-level cache, nor does it implement transactional write-behind or automatic dirty checking, nor do operations cascade to associated instances. Collections are ignored by a stateless session. Operations performed via a stateless session bypass Hibernate's event model and interceptors. Stateless sessions are vulnerable to data aliasing effects, due to the lack of a first-level cache.
For certain kinds of transactions, a stateless session may perform slightly faster than a stateful session.
Christian Bauer:
So write a custom interceptor that does nothing on isDirty(). Please continue asking usage questions on the user forum.
|