I'd think you'd do something like:
Code:
@Entity
@Table( name="People" )
class Person {
@Id @GeneratedValue
@Column( name = "PERSON_ID" )
private Long id; // Surrogate Key for Hibernate
@OneToMany( mappedBy = "parentPerson", cascade = CascadeType.ALL )
@Cascade( org.hibernate.annotations.CascadeType.DELETE_ORPHAN )
private List<Address> addresses = new ArrayList<Address>();
// Remember to write your helpers!
}
And on the other side:
Code:
@Entity
@Table( name="Addresses" )
class Address {
@Id @GeneratedValue
@Column( name = "ADDRESS_ID" )
private Long id; // Surrogate Key for Hibernate
@ManyToOne( targetEntity = Person.class )
private Person parentPerson;
// Remember to write your helpers!
}
And I suspect your HQL would look very close to:
"
select MAX(id) from Address where parentPerson = :person_id"