import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
/*
* Copyright 2006 James A Farley
*/
// Annotate this as a persistent entity
@Entity
// Specify the physical table name (danger, giving up some portability here)
@Table(name="HRT_PERSON")
public class Person implements Serializable {
private Long id;
private String mName;
private Collection<Address> mAddresses = new ArrayList<Address>();
// Persistent name property
public String getName() { return mName; }
public void setName(String name) { mName = name; }
// No-arg constructor
public Person() {}
// Annotate this property as the "primary key"
@Id
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
// Annotate this as a one-to-many persistent relationship
@OneToMany
public Collection<Address> getAddresses() {
return mAddresses;
}
public void setAddresses(Collection<Address> addrs) {
mAddresses = addrs;
}
// This method is a business method to add a single Address.
// The persistence engine won't use it, but clients can.
public void addAddress(Address a) {
mAddresses.add(a);
}
}
|