Reputation: 3047
I have a CollectionTable looking like this:
@ElementCollection
@CollectionTable(
name="FOO_FEES",
joinColumns=@JoinColumn(name="FOO_ID",
foreignKey=@ForeignKey(name="FK_FEE_FOO")),
indexes={
@Index(columnList="FEE", name="IDX_FEES_FEE"),
@Index(columnList="FOO_ID", name="IDX_FEES_FOO_ID")
}
)
@Column(name="FEE", nullable = false)
private Set<String> fees;
It works fine. The problem is that I want to set the action on cascade delete. But I don't know the syntax.
Upvotes: 0
Views: 313
Reputation: 134
It should work when you delete the parent object.
https://en.wikibooks.org/wiki/Java_Persistence/ElementCollection
The limitations of using an ElementCollection instead of a OneToMany is that the target objects cannot be queried, persisted, merged independently of their parent object. They are strictly privately-owned (dependent) objects, the same as an Embedded mapping. There is no cascade option on an ElementCollection, the target objects are always persisted, merged, removed with their parent. ElementCollection still can use a fetch type and defaults to LAZY the same as other collection mappings.
Upvotes: 0