package org.jboss.seam.rest.examples.tasks.entity; import java.util.List; 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.NamedQueries; import javax.persistence.NamedQuery; import javax.persistence.OneToMany; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import javax.xml.bind.annotation.XmlTransient; /** * @author <a href="http://community.jboss.org/people/jharting">Jozef Hartinger</a> */ @Entity @NamedQueries({ @NamedQuery(name = "categoryByName", query = "select category from Category category where category.name = :category"), @NamedQuery(name = "categories", query = "select category from Category category order by category.id")}) public class Category { private Long id; private String name; private List<Task> tasks; public Category() { } public Category(String name) { this.name = name; } @Id @GeneratedValue @XmlTransient public Long getId() { return id; } public void setId(Long id) { this.id = id; } @NotNull @Column(unique = true) @Size(min = 1, max = 100) public String getName() { return name; } public void setName(String name) { this.name = name; } @OneToMany(mappedBy = "category", cascade = {CascadeType.ALL}, fetch = FetchType.EAGER) @XmlTransient public List<Task> getTasks() { return tasks; } public void setTasks(List<Task> tasks) { this.tasks = tasks; } }