When a @ManyToOne relation is present on a composite key, Hibernate tries to persist that object even if no persist operation is done on the parent entity. This cause PersistentObjectException when an entity is retrieved from cache and Hibernate tries to persist its detached @ManyToOne key.
A first query.getSingleResult() works, but all subsequent ones throw this:
I've looked at the attached test and this issue does not appear to be related to load plans.
I know that the test case I provided isn't exactly the same as the issue presented by the creator here, but it is the same bug where the fk part of the composite key is persisted in all cases where this fk entity is detached. It don't think it matters if cache is enabled or not.
Somehow, when trying to retrieve the ID of an entity with a composite pk which includes a fk, the IncrediblySillyJpaMapsIdMappedIdentifierValueMarshaller needs to look in the db to find the entity since it's not in the context. I think to problem here is that it doesn't check if there is a cascade or not on the fk entity.
also involves a key-many-to-one.
Yes, I believe there could be several scenarios all tracing back to this same bug when using a key-many-to-one.
Fixed by in master and 5.1 branches. Thanks for the test case!