Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Correct way to set foreign keys for Mapping

I have the following classes and mappings
 
Class Order {
 
//this will reference one of the items from the items List below.
@OneToOne
Items topItem;
 
@OneToMany(mappedby="orderP" , cascade=CascadeType.ALL)
List<Items> items = new ArrayList<Items>
 
}
 
Class Items {
@ManyToOne()
Order orderP;
 
}
 
And in the db I have in table Order : topItem_id foreignKey references Items(id)
 
and for table Items have the : orderP_id foreignKey references Order(id)
 
Now when I delete the entity Order using remove(order), the items List all get cascaded for delete , but a foreign key violation is thrown for topItem_id , so to resolve this do we just remove/not use the foreign key constraint on topItem_id ?
 
But then the constraint was placed so that we dont insert an item_id that does not exist.

Back to the top