views:

67

answers:

0

hello i'm not sure whether the title depicts the my situation very well.I'm developing a user and contact managment system with hibernate. i have an UserAccount pojo, contact pojo and phone object.i limited it to 3 since since those are in concern.UserAccount has a bidirectional with contact, and both have unidirectional with phone pojo. i wanted to put unique on contact properties first name and phone.well if phone was a field in the contact table it will be a piece of cake,i would certainly override the equals and hascode and i would use for the database:

@Table(name="CONTACT", uniqueConstraints={@UniqueConstraint(columnNames="FIRST_NAME, PHONE")})

but it's map with set what i've not seen yet, but that is a requirement.another problem will be overriding the equals and hashcode.SO here is the pojos

// UserAccount pojo
@OneToMany(targetEntity=PhoneImpl.class, cascade= {CascadeType.ALL})
@org.hibernate.annotations.Cascade(value=org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
private Set<Phone> phones = new HashSet<Phone>();

@OneToMany(targetEntity=ContactImpl.class, cascade={CascadeType.ALL}, mappedBy="userAccount")
@org.hibernate.annotations.Cascade(value=org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
private Set<Contact> contacts = new HashSet<Contact>();

// Contact pojo
@ManyToOne(targetEntity=UserAccountImpl.class)
@JoinColumn(name="USER_ACCOUNT_ID",nullable=false)
private UserAccount userAccount;

@Column(name="FIRST_NAME", length=100)
private String firstName;

@OneToMany(targetEntity=PhoneImpl.class, cascade={CascadeType.ALL})
private Set<Phone> phones = new HashSet<Phone>();

i've been looking for a way on the net but it's like i don't write the proper key words or there is lack of information.Does any one have an idea about this and about how to write hashcode for this situation (meaning one of the field being a Set) thanks for reading