I need to write an EntityBean that holds a collection of EntityBeans of another type plus two single references to EntityBeans of that type. A simple example would be a customer who has a work address and a home address, and a collection of previously used addresses that also need to be stored.
The classes could look like this:
@Entity public class Customer implements Serializable { private Integer id; ... private Address homeAddress; private Address workAddress; private Address[] previousAddresses; ... @CollectionOfElements @IndexColumn(name="index1") public Address[] getPreviousAddresses() { return previousAddresses(); } @OneToOne public Address getHomeAddress() { return homeAddress; } @OneToOne public Address getWorkAddress() { return workAddress; } ... } @Entity public class Address implements Serializable { private Integer id; ... }