/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package ee.tlu.htk.dippler.entities; import java.io.Serializable; import java.util.Collection; import javax.persistence.Basic; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.ManyToOne; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; import javax.persistence.OneToMany; import javax.persistence.OneToOne; import javax.persistence.Table; import javax.persistence.TableGenerator; import javax.persistence.Transient; import javax.xml.bind.annotation.XmlRootElement; /** * * @author metz */ @XmlRootElement @Entity @Table(name = "learner") @NamedQueries({ @NamedQuery(name = "Learner.findAll", query = "SELECT l FROM Learner l"), @NamedQuery(name = "Learner.findById", query = "SELECT l FROM Learner l WHERE l.id = :id"), }) public class Learner implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(generator = "LearnerID") @TableGenerator(name="LearnerID", table="id_gen", pkColumnName="ID_NAME", valueColumnName = "ID_VAL", pkColumnValue="LAST_LEARNER", allocationSize=1) @Basic(optional = false) @Column(name = "id") private Long id; @Transient private Long user_id; @Transient private Long courseId; @Column(name = "status") private Integer status; @ManyToOne @JoinColumn(name="learner", referencedColumnName="id") private User user; @ManyToOne @JoinColumn(name="course", referencedColumnName="id") private Course course; @OneToMany @JoinTable(name = "coursegroup_member", joinColumns = @JoinColumn(name = "learner", referencedColumnName="id"), inverseJoinColumns = @JoinColumn(name = "coursegroup", referencedColumnName="id") ) private Collection groups; @OneToOne(cascade = CascadeType.PERSIST, mappedBy = "learner") private Grade grade; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public Integer getStatus() { return status; } public void setStatus(Integer status) { this.status = status; } public User getUser() { return user; } public void setUser(User u) { this.user = u; } public Course getCourse() { return course; } public void setCourse(Course c) { this.course = c; if ( !this.course.getLearners().contains(this) ) { this.course.addLearner(this); } } public Long getUser_id() { return user_id; } public void setUser_id(Long user_id) { this.user_id = user_id; } public Long getCourseId() { return courseId; } public void setCourseId(Long cid) { this.courseId = cid; } public Collection getGroups() { return groups; } public void setGroups(Collection groups) { this.groups = groups; } public Grade getGrade() { return grade; } public void setGrade(Grade grade) { this.grade = grade; } @Override public int hashCode() { int hash = 0; hash += (id != null ? id.hashCode() : 0); return hash; } @Override public boolean equals(Object object) { // TODO: Warning - this method won't work in the case the id fields are not set if (!(object instanceof Learner)) { return false; } Learner other = (Learner) object; if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) { return false; } return true; } @Override public String toString() { return "ee.tlu.htk.dippler.entities.Learner[id=" + id + "]"; } }