Persist of detached entity in derived ID

Description

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.

For example:

A first query.getSingleResult() works, but all subsequent ones throw this:

Attachments

1

Activity

Show:

Former user December 15, 2016 at 8:11 PM

Fixed by in master and 5.1 branches. Thanks for the test case!

Patrik Bakken December 15, 2016 at 1:26 AM

Yes, I believe there could be several scenarios all tracing back to this same bug when using a key-many-to-one.

Former user December 15, 2016 at 12:03 AM

also involves a key-many-to-one.

Patrik Bakken December 9, 2016 at 8:59 AM

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.

Former user December 9, 2016 at 4:34 AM

I've looked at the attached test and this issue does not appear to be related to load plans.

Fixed

Details

Assignee

Reporter

Labels

Components

Fix versions

Affects versions

Priority

Created March 17, 2016 at 1:04 PM
Updated December 20, 2016 at 10:15 AM
Resolved December 15, 2016 at 8:11 PM