users@glassfish.java.net

Re: How can I implement this relationship

From: <glassfish_at_javadesktop.org>
Date: Sun, 21 Dec 2008 09:21:56 PST

[code]
@Entity
@Table(name = "phones")
public class Phone implements Serializable {
@ManyToOne
@JoinColumns({
@JoinColumn(name="idEntidad", referencedColumnName="ID"),
@JoinColumn(name=""entidad", referencedColumnName="ID")
})
private Customer customer;
}
[/code]

I think in this way doesn't work fine, because in the case of Customers ,field 'entidad' always must be have the constant value 'CUSTOMER'.
This fails with this example:
Customers table:
id name
1 Michael

Employees table:
id name
1 Maria
2 Kevin

Phones tabla
id entidad idEntidad type number
1 CUSTOMER 1 HOME 655215487
2 CUSTOMER 1 OFFICE 985663322
3 EMPLOYEE 1 HOME 633524178
4 EMPLEYEE 2 HOME 984663366

To get all the phones of Michael in the JoinColumn I have to fix entidad to 'CUSTOMER' and bind phones.idEntidad with customers.id.

Thanks for all replies.
[Message sent by forum member 'tonhinbm' (tonhinbm)]

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