I have two entities. “Price” class has “CalculableValue” stored as SortedMap field.
In order to support sorted map I wrote customizer. After that, it seems @CascadeOnDelete is not working. If I remove CalculableValue instance from map and then save “Price” EclipseLink only updates priceId column to NULL in calculableValues table…
I really want to keep the SortedMap. It helps to avoid lots of routine work for values access on Java level.
Also, there is no back-reference (ManyToOne) defined in the CalculableValue class, it will never be required for application logic, so, wanted to keep it just one way.
Any ideas what is the best way to resolve this issue? I actually have lots of other dependencies like this and pretty much everything is OneToMany relation with values stored in sorted map.
Price.java:
@Entity
@Table(uniqueConstraints={
@UniqueConstraint(columnNames={"symbol", "datestring", "timestring"})
})
@Customizer(CustomDescriptorCustomizer.class)
public class Price extends CommonWithDate
{
...
@CascadeOnDelete
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@MapKeyColumn(name="key")
@JoinColumn(name = "priceId")
private Map<String, CalculatedValue> calculatedValues =
new TreeMap<String, CalculatedValue>();
...
}
public class CustomDescriptorCustomizer implements DescriptorCustomizer
{
@Override
public void customize(ClassDescriptor descriptor) throws Exception
{
DatabaseMapping jpaMapping = descriptor.getMappingByAttribute("calculatedValues");
((ContainerMapping) mapping).useMapClass(TreeMap.class, methodName);
}
}
Your customizer should have no affect on this. It could be because you are using a @JoinColumn instead of using a mappedBy which should normally be used in a @OneToMany.
You can check the mapping in your customizer using, isCascadeOnDeleteSetOnDatabase()
or set it using
mapping.setIsCascadeOnDeleteSetOnDatabase(true)