Saving entity with a onetomany collection fail the validation

Description

Hi.
I’ve a problem with entity, collection and validation.

My entities are (Getter and setter in the entities class are omitted):

I want to save the entity A.
Before saving it, i put in the bs collection some data.
I also call the validate method on A before the save and it validates without problem.
Next, i call the save method but it failes because the validation @NotEmpty on bs.

I’ve look at DefaultMergeEventListener code and i presume that the problem is at method entityIsTransient:

The first copyValues call (line 7) does not copy the bs collection from entity to copy object.
When the saveTransientEntity is called (line 9) the validation is triggered but the collection is empty.

It is a bug or a wanted behaviour?
What can i do?

 

Thanks

Environment

java 17, spring boot 3.1.1, spring-data-jpa 3.1.1, hibernate core 6.2.5.Final, hibernate validator 8.0.0.Final

Activity

Show:

Marko Bekhta October 28, 2024 at 4:41 PM

Closing as not a Hibernate Validator issue; a corresponding ORM issue is opened under https://hibernate.atlassian.net/browse/HHH-16921

Marko Bekhta July 11, 2023 at 12:31 PM

Hey thanks for reporting the issue.

We wouldn’t be able to do much on the Validator side since a test based on your example:

works fine. I have also checked if the issue can be reproduced within Hibernate ORM by running a simple test:

Works OK as well. And if Collections.singleton( b ) is replaced with a null or an empty collection – the validation is triggered and results in a constraint violation.

Hence, it seems that the problem might be in how Spring integrates Hibernate ORM.

I see that you’ve already created an HHH issue, so could you try to create a reproducer using this template and attach it to that HHH ticket so that the ORM team can look into that. If you’ll have trouble creating a reproducer using that template, you could also make your reproducer with Spring.

Cannot Reproduce

Details

Assignee

Reporter

Labels

Bug Testcase Reminder (view)

Bug reports should generally be accompanied by a test case!

Bug Testcase Reminder (edit)

Bug reports should generally be accompanied by a test case!

Participants

Alessandro Locatelli
Marko Bekhta

Components

Affects versions

Priority

Created July 11, 2023 at 10:40 AM
Updated October 28, 2024 at 4:41 PM
Resolved October 28, 2024 at 4:41 PM