Java Tutorial/JPA/Version

Материал из Java эксперт
Перейти к: навигация, поиск

Versioning Entity

File: Department.java



import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
@Entity
public class Department {
    @Id 
    private int id;
    private String name;
    @OneToMany(mappedBy="department")
    private Collection<Employee> employees;
    public Department() {
        employees = new ArrayList<Employee>();
    }
    
    public int getId() {
        return id;
    }
    
    public void setId(int id) {
        this.id = id;
    }
    
    public String getName() {
        return name;
    }
    
    public void setName(String deptName) {
        this.name = deptName;
    }
    
    public void removeEmployee(Employee employee) {
        getEmployees().remove(employee);
    }
    
    public Collection<Employee> getEmployees() {
        return employees;
    }
    public String toString() {
        return "Department id: " + getId() + 
               ", name: " + getName();
    }
}