Cascade unexpected behavior

Hi Hibernate developers,
I’ve got a question regarding the Hibernate 6 behavior. In version 5 we had an entity with relation like below and there was no problem. Now it’s impossible to do this without first persisting B1 and B2 and then adding the reference from B1 to B2.

A is managed entity. B1 and B2 are new objects of the same type.
A has a collection of B1, B2 (collection has cascade SAVE_UPDATE/PERSIST), in the same trascation we also create add a reference of B2 into B1 (this relation has no cascade). So we end up with A → collection B1, B2 and B1 referencing B2.

During flush B1 is persisted, but complains about B2 not being persisted. I wonder why this does not work anymore in version 6? Is this because version 6 is now more strict?

Caused by: org.hibernate.TransientPropertyValueException: object references an unsaved transient instance - save the transient instance before flushing

Did you try with the latest ORM 6.4 version already? If so and the problem persists, please try to create a reproducer with our test case template and if you are able to reproduce the issue, create a bug ticket in our issue tracker and attach that reproducer.

we get this in the latest 6.5.2.Final - (worked in 5) - the order it is dealing with multiple relationships is wrong - it must have previously found the relationship with cascade=persist before looking at the non-owning/cascade=none relationship. Now it fails because it must look at that non-owning/cascade=none relationship first. (or we have to change the mapping somehow!?)

@mira-silhavy Hi, is this still an issue for you?

Please create a reproducer and attach that to a newly create Jira issue.

Hi @Michael_McGovern, I don’t remember exactly. But we don’t have that problem anymore. We’ve had to change some code to comply with JPA persist cascade behavior that is the default in hibernate 6.

@mira-silhavy Thanks, you don’t happen to recall what the changes to cascade behaviour where?

Thanks, FYI I was not able to reproduce initially in the test template - until changed to the JPA unit test - the jpaBootstrap to true - then i get the error - so the PERSIST_ON_FLUSH cascading action is giving the error where the SAVE_UPDATE cascading action works ok.

Hi @Michael_McGovern, jpaBootstrap caused us some headaches. But I guess all of that was because we got used to hibernate less strict behavior. With new behavior it forced us to study and understand the standard JPA behavior, e.g. when we call persist, when we create relations and that we cannot work with detached entities the same way as before.
I’d say hibernate 5 was a lot more benevolent, it was more fool-proof. Good old hibernate 5 times are over now and we have to learn hibernate all over again :slight_smile: