This is a quite trick problem that only occurs on modified lazy collections that aren't initialized
( Like when you do a add() operation without any previous size() or get() or toString() ... )
I think that it will be easier to show it by a commented source.
I made a little database (with only 3 simple tables to make possible to reproduce the error.) + a maven project
The maven project have 2 file called pom33.xml and pom35.xml so it's possible to easily see how the error occurs on 3.3.2 but not on 3.5.6
the script to recreate the problem is available within the project too.
BTW the source do a rollback ( So it won't change the database ).
If you want changes on db it will be necessary to change the rollback() to commit()
This problem occurs on hibernate 3.3.2 and 3.3.1
( The latest JPA1 hibernate implementations I've found )
Oh I forgot to inform that this error occurs only when we have cascade DELETE_ORPHAN.
( the exception is thrown from AbstractPersistentCollection.getOrphans() when trying to run a ForeignKeys.getEntityIdentifierIfNotUnsaved() )
Is this still a problem in 4.1.3?
No it works fine on 4.1.3.
It seems to be fixed on all newer versions of hibernate since 3.5.6.
Anyway I think It's quite important to have an bug free JPA 1 implementation since hibernate 4.1.3 don't work with legacy persistence-api-1.0 API.
This way software solutions stuck on persistence 1.0 (maybe for classloader hierarchy sharing inside a application service maybe for other reasons) can go on.
Community 3.3.x is no longer supported.