users@glassfish.java.net

Re: JPA Question : Deletion w.r.t One-to-many relation

From: <glassfish_at_javadesktop.org>
Date: Fri, 18 May 2007 11:35:18 PDT

The Many side in a One-To-Many relationship always has the foreign key, and can be removed without affecting the referenced row on the One side. The reverse is not true: As all rows on the Many side reference one row on the One side, the foreign key on the Many side must be nullified, before the One side can be removed.

I JPA,however, please note that the relationship should be maintained on both sides, i.e.

t2.setT1(null);
t1.getT2s().remove(t2);

if t1 and t2 are POJO instances mapped to tables t1 and t2 respectively.
[Message sent by forum member 'mf125085' (mf125085)]

http://forums.java.net/jive/thread.jspa?messageID=217887