I created a custom IdentifierGenerator which verifies that the ID it generates does not yet exist in the database, before returning it (if it does, it tries generating a different one.)
However, when the query to verify the (non)existence of the newly generated ID is issued, it automatically causes another Flush() to occur. The 2nd Flush() tries to generate keys for all transient entities to be saved, causing infinite recursion. :(
I don't see anything in the documentation (even in Hibernate's documentation) that says you're not supposed to use the session passed to IIdentifierGenerator.Generate() to query anything. (What would you use it for otherwise?)
How can this be done? Should I be verifying the new ID in a different session?
|