users@glassfish.java.net

Re: Foreign key not being created in child entity

From: Markus Fuchs <Markus.Fuchs_at_Sun.COM>
Date: Mon, 16 Apr 2007 11:54:54 -0700

Hi,

JPA recommends to always maintain relationships on both sides. In your
case, please also set the relationship on the Payee side. Besides,
relationships must always be set on the "owning" side, which is Payee.

HTH,

-- markus.

glassfish_at_javadesktop.org wrote:
> I have two entities that have a one to many relationship.The parent entity's primary key is a foreign key in the child entity.These are mapped as shown below in the code snippet:
>
> public abstract class Claimant implements Serializable {
> private static final long serialVersionUID = -811235823828480105L;
>
> @Id
> @GeneratedValue(strategy = GenerationType.TABLE)
> @Column(name = "ID")
> protected Long id;
>
> @OneToMany(mappedBy="claimant",cascade=CascadeType.ALL,targetEntity=Payee.class)
> protected Collection<? extends Payee> payees;
>
>
> and then in the Payee class :
>
> public abstract class Payee implements Serializable {
> @Id
> @GeneratedValue(strategy = GenerationType.TABLE)
> @Column(name = "ID")
> protected Long id;
>
> @ManyToOne
> @JoinColumn(name = "CLAIMANT_ID")
> private Claimant claimant;
>
>
> When I persist a Claimant entity , the attached Payee get persisted , but the Claimant entity's primary key is not written to the Payee tables "CLAIMANT_ID" column.
>
> What am missing?
> [Message sent by forum member 'jeffmutonho' (jeffmutonho)]
>
> http://forums.java.net/jive/thread.jspa?messageID=212521
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>