|
It appears that in the annotation manual there is:
"Mapping composite primary and foreign keys"
But I seem to be getting some cascade saving problems:
I have the folowing:
@Embeddable
class CompositeId {
private Long id;
private String type;
}
class B {
@Id
private Long id;
}
class A {
@Id
CompositeId id;
@OneToMany(cascade =
{CascadeType.PERSIST,CascadeType.MERGE })
@JoinTable(
name="JoinTable",
joinColumns = {
@JoinColumn(name="aId", referencedColumnName = "id"),
@JoinColumn(name="aType", referencedColumnName = "type"),
},
inverseJoinColumns = @JoinColumn( name="bId"))
@IndexColumn(name="index")
Collection<B> children;
}
But I'm getting a foreign key constratint violation on table B on column id. When I enabled show_sql=true I noticed that it is doing the following:
1) Inserting row for table A
2) It then tries to insert row on JoinTable -- fails because it has a foreign key constraint on Table B
how do I set this so that row in table A gets inserted first, then row in table B then row in JoinTable.
any help would be much appreciated.
|