In a Transaction, Delete on unindexed entities referenced by indexed entities with ContainedIn throw LazyInitializationException


Delete on unindexed entities referenced by indexed entities with ContainedIn annotation failed.

On PostCommit Transaction, I get a LazyInitializationException on the collection with the ContainedIn annotation.

I upload a test case to reproduce this, run the Boot class.

1/ Entity2 is not lacking @DocumentId, I read the doc again and again (my english is very poor, but ...) : "In fact since the 3.1.0 release of Hibernate Search @DocumentId is optional in the case where an @Id annotation exists."
2/ Entity2 is not lacking @IndexedEmbedded, see the "entity1" association.
3/ From Hibernate Entity Manager Doc : "In an EXTENDED persistence context, all read only operations of the entity manager can be executed outside a transaction (find(), getReference(), refresh(), and read queries). Some modifications operations can be executed outside a transaction, but they are queued until the persistence context join a transaction. This is the case of persist(), merge(), remove(). Some operations cannot be called outside a transaction: flush(), lock(), and update/delete queries.". This is the case of the attached test. I attach a second testcase with all the operation in a transaction, the result is the same.
4/ I check 3.1.1-GA, the problem occurs alway.
5/ All the operation are in a transaction.

Please read and run my testcase and if I missuse hibernate say me where.

I can't reopen the bug HSEARCH-342, I open a new bug because the resolution of the bug don't resolve this problem.

Thank you.


Hibernate 3.3.1.GA, PostgreSQL 8.3


Emmanuel Bernard


Grégoire Rolland



Suitable for new contributors


Pull Request


Feedback Requested


Fix versions

Affects versions