/* * 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.Date; import javax.persistence.Basic; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; import javax.persistence.OneToOne; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Transient; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; /** * * @author pjotr */ @Entity @Table(name = "grade") @XmlRootElement @NamedQueries({ @NamedQuery(name = "Grade.findAll", query = "SELECT g FROM Grade g"), @NamedQuery(name = "Grade.findById", query = "SELECT g FROM Grade g WHERE g.id = :id"), @NamedQuery(name = "Grade.findByLearner", query = "SELECT g FROM Grade g WHERE g.learner = :learner"), @NamedQuery(name = "Grade.findByCourse", query="SELECT g FROM Grade g WHERE g.learner.course = :course"), @NamedQuery(name = "Grde.findByUserAndCourseIds", query = "SELECT g FROM Grade g WHERE g.learner.user.id = :user_id AND g.learner.course.id = :course_id")}) public class Grade implements Serializable { private static final long serialVersionUID = 1L; @Id @Basic(optional = false) @NotNull @Column(name = "learner_id") private Long id; @Basic(optional = false) @NotNull @Size(min = 1, max = 10) @Column(name = "grade") private String grade; @Basic(optional = false) @NotNull @Size(min = 0, max = 255) @Column(name = "feedback") private String feedback; @Basic(optional = false) @NotNull @Column(name = "created") @Temporal(TemporalType.TIMESTAMP) private Date created; @Basic(optional = false) @NotNull @Column(name = "modified") @Temporal(TemporalType.TIMESTAMP) private Date modified; @JoinColumn(name = "learner_id", referencedColumnName = "id", insertable = false, updatable = false) @OneToOne(optional = false) private Learner learner; @Transient @XmlElement(name="course_id") public Long course_id; @Transient @XmlElement(name="user_id") public Long user_id; public Grade() { } public Grade(Long id) { this.id = id; } public Grade(Long id, String grade, String feedback, Date created, Date modified) { this.id = id; this.grade = grade; this.feedback = feedback; this.created = created; this.modified = modified; } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getGrade() { return grade; } public void setGrade(String grade) { this.grade = grade; } public String getFeedback() { return feedback; } public void setFeedback(String feedback) { this.feedback = feedback; } public Date getCreated() { return created; } public void setCreated(Date created) { this.created = created; } public Date getModified() { return modified; } public void setModified(Date modified) { this.modified = modified; } public Learner getLearner() { return learner; } public void setLearner(Learner learner) { this.learner = learner; } @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 Grade)) { return false; } Grade other = (Grade) 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.Grade[ id=" + id + " ]"; } }