Hi
I have an object (Client) that has a list of addresses. I want that the client have a main address, a billing address and a shipping address, all contained in the list of addresses. How can i reference those type of address without
Code:
@Entity()
@Table(name="Clients")
public class Client extends BasePersistentObject {
private static Logger log = Logger.getLogger(Client.class);
@Id
@Column(name="Id")
@GeneratedValue(strategy=GenerationType.AUTO)
private long id;
@Column(name="companyName")
private String companyName;
@OneToMany(mappedBy="client", cascade=CascadeType.ALL)
private List<Address> addresses;
// What annotations? Should reference to an object of the addresses list.
private Address mainAddress;
// What annotations? Should reference to an object of the addresses list.
private Address billingAddress;
// What annotations? Should reference to an object of the addresses list.
private Address shippingAddress;
// The rest of methods, contructors, getters and setters.
}
The address class is very simple:
Code:
@Entity()
@Table(name="Addresses")
public class Address extends BasePersistentObject {
@Id
@Column(name="Id")
@GeneratedValue(strategy=GenerationType.AUTO)
private long id;
@ManyToOne()
@JoinColumn(name="Client_ID", nullable=false)
private Client client;
@Column(name="Address")
private String address;
// ...
}
Should I add new fields to the database? What is the best method to do this? Thanks in advance.
Hibernate version: 3.2.3
Name and version of the database you are using: MySQL 5.0, Windows XP SP2 Professional