Don't change the reference to a collection with delete-orphan enabled

I get the error Don’t change the reference to a collection with delete-orphan enabled for no particular reason.

A bit of input: I have a class Register which has a ManyToOne relation

@JoinColumns({ @JoinColumn(name = “MTR_ID”, referencedColumnName = “MTR_ID”, nullable = true), @JoinColumn(name = “EFF_DTTM”, referencedColumnName = “EFF_DTTM”, nullable = true) })
	@ManyToOne(optional = true, fetch = FetchType.LAZY)
	private MeterConfiguration meterConfiguration;

It is important to note that MTR_ID and EFF_DTTM are not primary keys in the MeterConfiguration

If I load Register from the database and then do flash, I get an error: Don’t change the reference to a collection with delete-orphan enabled

The reason is that in the org.hibernate.engine.internal.Collections#processReachableCollection method, the CollectionEntry loadedKey is MeterConfiguration(*null*) and
currentKey is MeterConfiguration(*someId*).

MeterConfiguration(*null*) entity looks like a proxy, initialized with only two fields, which are specified in JoinColumns

And loadedKey is set in org.hibernate.engine.internal.StatefulPersistenceContext#addUninitializedCollection when initializing a collection.

I don’t delete or change the reference, the problem is that initially loadedKey and currentKey are already different

This started after upgrading to Hibernate 6. Earlier, in version 5, this code worked.

I still think the error is on my side, but I can’t figure out what I’m doing wrong

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.

Hi. This will take some time, I was hoping that since the error is probably on my side I could get some quick advice on the cause.

If I can’t solve it, I’ll follow your example