users@glassfish.java.net

Re: JPA - One to Many persistence issue

From: <glassfish_at_javadesktop.org>
Date: Mon, 14 Dec 2009 11:29:12 PST

You need to define cascade type on personnel entity as this entity is the source entity and owner of the relationship.

In personnel entity , you need to define relationship like below

@ManyToOne(cascade=CascadeType.ALL)
private Company company;

After that You need first persist Company in database then you need to persist personnel as this is many to one relationship. Company can exist without personal also.

em.persist(company)
personeel.setCompany(company)
em.persist(personal)

//commit the transation.
[Message sent by forum member 'xsunil_kumar' ]

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