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:

Environment

WildFly 10.0

Activity

Show:
Gail Badner
December 9, 2016, 4:34 AM

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

Patrik Bakken
December 9, 2016, 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.

Gail Badner
December 15, 2016, 12:03 AM

also involves a key-many-to-one.

Patrik Bakken
December 15, 2016, 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.

Gail Badner
December 15, 2016, 8:11 PM

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

Assignee

Gail Badner

Reporter

Giovanni Lovato

Fix versions

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

Priority

Blocker
Configure