Hibernate version: 3.2
I am using hibernate annotations to map the relationship between a department and its employees.
On the Department object I only want the employees list to hold the active employees (the ones that have an endDate that is null), how do I do that?
Here is the code for the department and employee, without getters/setters:
public class Department implements Serializable {
@Id @Column(name="id")
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SEQ_GEN")
private long id;
@Column(nullable=false, length=128)
private String name;
@Column(length=255)
private String description;
@Column(name="created_date", nullable=false, updatable=false)
private Date createdDate;
@Column(name="end_date")
private Date endDate;
....
@OneToMany(mappedBy="department")
private List<Employee> employees;
}
public class Employee implements Serializable {
@Id @Column(name="id")
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SEQ_GEN")
private long id;
@Column(name="first_name", nullable=false)
private String firstName;
@Column(name="last_name", nullable=false)
private String lastName;
private String email;
@Column(name="created_date", nullable=false, updatable=false)
private Date createdDate;
@Column(name="end_date")
private Date endDate;
@ManyToOne
@JoinColumn(name="department_id")
private Department department;
...
}
|