| The following NullPointerException happens when loading an entity with a eager @OneToMany field and enhanced with enableDirtyTracking = true. Without any enhancement it worked correctly. Got the following stacktrace during load:
My field declaration was:
@OneToMany(
cascade = CascadeType.ALL,
fetch = FetchType.EAGER,
targetEntity = MonitorField.class,
mappedBy = "parent"
)
private Collection<IMonitorField> innerFields = new ArrayList<IMonitorField>();
A workaround I found was overriding ArrayList's equals so it would not try to read PersistentBag data:
@OneToMany(
cascade = CascadeType.ALL,
fetch = FetchType.EAGER,
targetEntity = MonitorField.class,
mappedBy = "parent"
)
private Collection<IMonitorField> innerFields = new ArrayList<IMonitorField>()
{
@Override
public boolean equals(Object obj)
{
if (obj instanceof PersistentBag)
return false;
return super.equals(obj);
}
};
In StatefulPersistenceContext.getLoadedCollectionOwnerOrNull the NullPointerException happened because getCollectionEntry( collection ) at method's first line returned null. |