OneToMany CascadeType.REMOVE

Hello,
I have a mapping

public class Data {
....
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@OneToMany(cascade = CascadeType.REMOVE, fetch = FetchType.LAZY/*-, mappedBy = "userId"*/)
@JoinColumn(name = "userId")
public Set<MyData> getList() {
	return list;
}
....
}

There was an upgrade change where mappedBy = “userId” was replaced by @JoinColumn(name = “userId”).

When I delete Data records it is supposed to delete MyData also as its CascadeType.REMOVE. After the upgrade I now I get an exception:

org.hibernate.exception.ConstraintViolationException: could not execute statement [(conn=200) Column 'userid' cannot be null] [update my_data set userId=null where userId=?]

So rather than deleing the records it is trying to set the userid as null (which is not allowed in the db) rather than deleting the records.

Maybe I have got something wrong on the mapping change on the upgrade?

Any Ideas?

I am on version 6.4.2.Final.

Cheers Greg

As a test, I reinstated the original mappedBy and the cascade delete now works with no errors.

Possibly there have been some changes since the initial v6.

Please try to create a reproducer with our test case template (hibernate-test-case-templates/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java at main · hibernate/hibernate-test-case-templates · GitHub) and if you are able to reproduce the issue, create a bug ticket in our issue tracker(https://hibernate.atlassian.net) and attach that reproducer.

Went through and checked the db and found another lookup failure, it was failing silently when the @ManyToOne was null.

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "userName", insertable = false, updatable = false)
// @NotFound(action = NotFoundAction.IGNORE)
public MyData getGetData() {
	return myData;
}

I had also commented out the @NotFound(action = NotFoundAction.IGNORE). I would have only done this if hibernate was complaining and would not start.

I have now reinstated all the commented out not founds. Although the @OneToMany still complains, and improved my logging to catch these in the future. Passes all my tests for now.

If I have more errors I will try and do the reproducer.

Cheers