1. 程式人生 > >Spring整合Jpa框架

Spring整合Jpa框架

package site.lx.dnf.entity;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import
javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.OrderBy; import javax.persistence.Table; import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; /*** * 導航欄選單 * @author
Daniel * */
@Entity @Table(name="category") @Cache(usage= CacheConcurrencyStrategy.READ_WRITE) public class Category implements Serializable{ private static final long serialVersionUID = 2189694300886067425L; private Long id; private String name;//選單名稱 private String url;//連結地址 private
Integer level;//級別 private Integer sort; private Character status; private Category parentCategory; private Set<Category> childCategoryList = new HashSet<Category>();//二級選單集合 @Id @Column(name = "ID", unique = true, nullable = false) @GeneratedValue(strategy = GenerationType.IDENTITY) public Long getId() { return id; } public void setId(Long id) { this.id = id; } @Column(name="name",nullable=false,length=20) public String getName() { return name; } public void setName(String name) { this.name = name; } @Column(name="url") public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } @Column(name="level",unique=true,length=1) public Integer getLevel() { return level; } public void setLevel(Integer level) { this.level = level; } @Column(name="sort") public Integer getSort() { return sort; } public void setSort(Integer sort) { this.sort = sort; } @Column(name="status") public Character getStatus() { return status; } public void setStatus(Character status) { this.status = status; } @Cache(usage=CacheConcurrencyStrategy.READ_WRITE) @ManyToOne @JoinColumn(name="parentId") public Category getParentCategory() { return parentCategory; } public void setParentCategory(Category parentCategory) { this.parentCategory = parentCategory; } @Cache(usage=CacheConcurrencyStrategy.READ_WRITE) @OneToMany(mappedBy="parentCategory",fetch = FetchType.EAGER) @OrderBy(value="sort") public Set<Category> getChildCategoryList() { return childCategoryList; } public void setChildCategoryList(Set<Category> childCategoryList) { this.childCategoryList = childCategoryList; } @Override public String toString() { return "Category [id=" + id + ", name=" + name + ", level=" + level + "]"; } }