/* * 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 javax.persistence.Basic; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; import javax.persistence.Table; import javax.persistence.TableGenerator; import javax.persistence.Transient; import javax.xml.bind.annotation.XmlRootElement; /** * * @author metz */ @XmlRootElement @Entity @Table(name = "facilitator") @NamedQueries({ @NamedQuery(name = "Facilitator.findAll", query = "SELECT f FROM Facilitator f"), @NamedQuery(name = "Facilitator.findById", query = "SELECT f FROM Facilitator f WHERE f.id = :id"), @NamedQuery(name = "Facilitator.findByCourse", query = "SELECT f FROM Facilitator f WHERE f.course = :course") }) public class Facilitator implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(generator = "FaciliatatorID") @TableGenerator(name="FaciliatatorID", table="id_gen", pkColumnName="ID_NAME", valueColumnName = "ID_VAL", pkColumnValue="LAST_FACILITATOR", allocationSize=1) @Basic(optional = false) @Column(name = "id") private Long id; @Column(name = "facilitator", insertable=false, updatable=false) private Long user_id; //Is used in subquery, in User entity @Column(name = "status") private Integer status; @JoinColumn(name = "facilitator") @ManyToOne private User user; @JoinColumn(name = "course") @ManyToOne private Course course; @Transient private Long courseId; @Transient private String email; @Transient private Long userId; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public Course getCourse() { return course; } public void setCourse(Course course) { this.course = course; if ( !this.course.getFacilitators().contains(this) ) { this.course.addFacilitator(this); } } public Integer getStatus() { return status; } public void setStatus(Integer status) { this.status = status; } public User getUser() { return user; } public void setUser(User user) { this.user = user; if ( !this.user.getFacilitators().contains(this) ) { this.user.addFacilitator(this); } } public Long getCourseId() { return courseId; } public void setCourseId(Long cid) { this.courseId = cid; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public Long getUserId() { return userId; } public void setUserId(Long userId) { this.userId = userId; } @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 Facilitator)) { return false; } Facilitator other = (Facilitator) 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.Facilitator[id=" + id + "]"; } }