[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3220?page=c...
]
Dan Bisalputra commented on HHH-3220:
-------------------------------------
I was originally trying to implement a history/undo function in which a Hibernate
interceptor would save the previous state of dirty objects so that any change made to the
database could be undone. Stateless sessions were handy for saving the previous state of
a given object without triggering cascaded saves of its associations. I wrote the patch
because I was getting the assertion error even though I was accessing the database using a
single thread.
I abandoned this approach for two reasons: 1) it was too slow because every transaction
effectively had twice as much work to do, and 2) there was only a single history trail,
which meant that it might be necessary to undo a more recent change in a different part of
the database before undoing the desired change.
The solution I finally used was to restrict undoability to a small list of objects whose
editing operations were tricky to undo by hand. Each undoable object is associated with a
persistent list of history entries (designed along the lines of the Swing UndoableEdit
class). This approach does not give a comprehensive history like the first approach, but
it is faster and allows undos to occur without affecting unrelated objects.
So in the end, I did not do anything clever with stateless sessions, I just avoided the
problem by re-scoping my design to use Hibernate in a less exotic way.
Patch to prevent "org.hibernate.AssertionFailure: possible
non-threadsafe access to the session" error caused by stateless sessions
-----------------------------------------------------------------------------------------------------------------------------------
Key: HHH-3220
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3220
Project: Hibernate Core
Issue Type: Patch
Components: core
Affects Versions: 3.2.6
Environment: Hibernate 3.2.6, Apache Derby on Mac OSX & PC
Reporter: Dan Bisalputra
Priority: Minor
Attachments: StatelessSession-patch
When performing a query in a stateless session, the query loads objects in a two-phase
process in which a temporary persistence context is populated with empty objects in the
first phase, then the objects' member data are read from the database in the second
phase. If one of the objects contains an association or a collection, it performs a
recursive call to the session's get() method. The get() method clears the temporary
persistence context, so if the parent object contains any other associations to be read in
the second phase, Hibernate throws an assertion because they are not found in the
persistence context.
This patch solves the problem by only clearing the persistence context when the recursion
ends. It passes all the unit tests for our application, but I have not tested it with any
of the Hibernate unit tests.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira