|
I have a use-case with a nested transaction in a loop.
When the nested transaction is committed, I manually flush and clear the Hibernate-Session, because otherwise, the program would run into an OutOfMemoryException, because it loads to many objects into the Hibernate-Session.
Sometimes, the nested transaction is rolled back, to cancel some work, because of invalid data or other errors. In this case I have to clear the Hibernate-Session, so that the modified objects are not saved by Hibernate.
When the nested transaction is committed and I am flushing the HibernateSession, I can flush the FullTextSession accordingly via FullTextSession.flushToIndexes().
But, when the nested transaction has to be rolled back, I am not able to cancel the work recorded by the FullTextSession. FullTextSession.clear() has no effect on the queued work. This leads to errors: because I have flushed the Hibernate-Session manually, the queued work sometimes is causing LazyInitializationException's. And: it should not be written to the index, because I have thrown away the modified objects and the index would get out of sync, if the queued work is not canceled.
I searched the documentation and the internet for hours, but I can't find any way, to cancel work.
I think it would be reasonable, to overwrite Session.clear() in FullTextSession and cancel all queued work, like when the session is rolled back. Because, this is, what a user expects, when he clears the FullTextSession.
Another possibility would be, to implement a Method like FullTextSession.clearQueuedWork() or .cancelWork().
|