package com.jasonrudolph.ejb3example.entity; import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; import java.util.Date; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.OneToMany; import javax.persistence.Table; @Entity @Table(name = "employees") public class EmployeeBean implements Serializable { /** The primary key for this employee. */ private int id; /** The network ID (i.e., user ID) for this employee. */ private String networkId; /** The first name for this employee. */ private String firstName; /** The last name for this employee. */ private String lastName; /** The date on which this employee began his/her employment. */ private Date startDate; /** The collection of computers assigned to this employee. */ private Collection computers = new ArrayList(); public EmployeeBean() { } public EmployeeBean(String networkId, String firstName, String lastName, Date startDate) { this.networkId = networkId; this.firstName = firstName; this.lastName = lastName; this.startDate = startDate; } /** * @return the system-generated primary key for this employee */ @Id @GeneratedValue public int getId() { return this.id; } /** * Sets the primary key for this employee. Only the EJB container should * invoke this method. * * @param id * the primary key for this employee */ public void setId(int id) { this.id = id; } @Column(name = "network_id") public String getNetworkId() { return this.networkId; } public void setNetworkId(String networkId) { this.networkId = networkId; } @Column(name = "first_name") public String getFirstName() { return this.firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } @Column(name = "last_name") public String getLastName() { return this.lastName; } public void setLastName(String lastName) { this.lastName = lastName; } @Column(name = "start_date") public Date getStartDate() { return startDate; } public void setStartDate(Date startDate) { this.startDate = startDate; } /** * @return the collection of computers assigned to this employee */ @OneToMany(fetch = FetchType.EAGER, cascade = { CascadeType.ALL }, mappedBy = "employeeBean") public Collection getComputers() { return this.computers; } /** * Sets the collection of computers assigned to this employee. * * @param computers * the collection of computers assigned to this employee */ public void setComputers(Collection computers) { this.computers = computers; } }