Regression in 3.5.5: Cascade on merge for Sets fails with transient entities

Description

Something happened from 3.5.4 to 3.5.5. Here is regression issue we're experiencing after upgrade:

We have entities ResearchClientFile and ResearchVendorRecord.

RCF maps RVR:

@Sort(type = SortType.NATURAL)
@OneToMany(mappedBy = "file", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
public SortedSet<ResearchVendorRecord> getRecords() {
return records;
}

RVR maps RCF:

@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "research_client_file_id")
public ResearchClientFile getFile() {
return file;
}

The following unit test:

ResearchClientFile rcf = RandomUtils.randomBean(ResearchClientFile.class);
rcf.addRecord(RandomUtils.randomBean(ResearchVendorRecord.class));
rcf = session.merge(rcf);

produces the following exception in 3.5.5 but not in 3.5.4.:

java.lang.NullPointerException: null entities are not supported by org.hibernate.event.def.EventCache
at org.hibernate.event.def.EventCache.containsKey(EventCache.java:80)
at org.hibernate.event.def.DefaultMergeEventListener.mergeTransientEntity(DefaultMergeEventListener.java:361)
at org.hibernate.event.def.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:303)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:258)
at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:869)

equals, hashCode and compareTo are completely consistent in RVR.

The issue seems to affects only Set and SortedSets and on merge only. Lists (with bag semantics) do not appear to be affected on merge.

Environment

Hibernate 3.5.5, Oracle 10g.

Activity

Show:
Gail Badner
September 13, 2010, 11:01 PM

Kyrill, does ResearchClientFile.addRecord(ResearchVendorRecord record) contain the following?

records.add( record );
record.setFile( this );

If so, is there some other non-nullable entity property in your mapping that is null?

Kyrill Alyoshin
September 14, 2010, 12:09 AM

Oh, the entities are most certainly bi-directional. That's exactly what ResearchClientFile#addRecord(ResearchRecord) does.

Also RandomUtils.getBean() populates the bean with random values for all basic data types. I did test it on other entities as well. The issue is still there. I think it is important to keep in mind that everything works in 3.5.4. The app has been deployed in production for a few months now (on 3.5.2). So, things do work, they just break on 3.5.5. I believe it should be very easy to reproduce.

Gail Badner
September 14, 2010, 6:14 PM

Please do the following:

Thanks,
Gail

Kyrill Alyoshin
October 23, 2010, 12:01 AM

Gail, very sorry about this. Yes, there is another entity in ResearchVendorRecord that is marked as optional=false (but should not be). And it was screwing things up.

I guess I was puzzled that the problem suddenly showed up when we upgraded the jar.

You can close it as a non-issue. Now... If we only could get resolved, that'd be awesome!

Steve Ebersole
March 21, 2011, 7:08 PM

Bulk closing stale resolved issues

Rejected

Assignee

Gail Badner

Reporter

Kyrill Alyoshin

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure