Java tutorial
/** * Copyright © 2012-2013 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); */ package com.hongqiang.shop.modules.cms.entity; import java.util.Date; import java.util.List; import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToOne; import javax.persistence.Table; import javax.persistence.Transient; import javax.validation.Valid; import javax.validation.constraints.NotNull; import org.apache.commons.lang3.StringUtils; import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; import org.hibernate.annotations.DynamicInsert; import org.hibernate.annotations.DynamicUpdate; import org.hibernate.annotations.NotFound; import org.hibernate.annotations.NotFoundAction; import org.hibernate.search.annotations.Analyze; import org.hibernate.search.annotations.Analyzer; import org.hibernate.search.annotations.Field; import org.hibernate.search.annotations.Index; import org.hibernate.search.annotations.Indexed; import org.hibernate.search.annotations.IndexedEmbedded; import org.hibernate.search.annotations.Store; import org.hibernate.validator.constraints.Length; import org.wltea.analyzer.lucene.IKAnalyzer; import com.google.common.collect.Lists; import com.hongqiang.shop.common.persistence.DataEntity; /** * Entity * @author ThinkGem * @version 2013-05-15 */ @Entity @Table(name = "cms_article") @DynamicInsert @DynamicUpdate @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) @Indexed @Analyzer(impl = IKAnalyzer.class) public class Article extends DataEntity { private static final long serialVersionUID = 1L; private Long id; // ? private Category category;// ? private String title; // private String color; // redgreenblue?yelloworange private String image; // private String keywords;// private String description;// ???? private Integer weight; // ???? private Date weightDate;// ????weight0 private Integer hits; // private String posid; // ???12??? private ArticleData articleData; // public Article() { super(); this.weight = 0; this.hits = 0; this.posid = ""; } public Article(Long id) { this(); this.id = id; } public Article(Category category) { this(); this.category = category; } @Id @GeneratedValue(strategy = GenerationType.AUTO) // @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_cms_article") // @SequenceGenerator(name = "seq_cms_article", sequenceName = "seq_cms_article") public Long getId() { return id; } public void setId(Long id) { this.id = id; } @ManyToOne @JoinColumn(name = "category_id") @NotFound(action = NotFoundAction.IGNORE) @NotNull public Category getCategory() { return category; } public void setCategory(Category category) { this.category = category; } @Length(min = 1, max = 255) @Field(index = Index.YES, analyze = Analyze.YES, store = Store.NO) public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } @Length(min = 0, max = 50) public String getColor() { return color; } public void setColor(String color) { this.color = color; } @Length(min = 0, max = 255) public String getImage() { return image; } public void setImage(String image) { this.image = image; } @Length(min = 0, max = 255) @Field(index = Index.YES, analyze = Analyze.YES, store = Store.NO) public String getKeywords() { return keywords; } public void setKeywords(String keywords) { this.keywords = keywords; } @Length(min = 0, max = 255) @Field(index = Index.YES, analyze = Analyze.YES, store = Store.NO) public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } @NotNull public Integer getWeight() { return weight; } public void setWeight(Integer weight) { this.weight = weight; } public Date getWeightDate() { return weightDate; } public void setWeightDate(Date weightDate) { this.weightDate = weightDate; } public Integer getHits() { return hits; } public void setHits(Integer hits) { this.hits = hits; } @Length(min = 0, max = 10) public String getPosid() { return posid; } public void setPosid(String posid) { this.posid = posid; } @OneToOne(mappedBy = "article", cascade = CascadeType.ALL, optional = false) @IndexedEmbedded @Valid public ArticleData getArticleData() { return articleData; } public void setArticleData(ArticleData articleData) { this.articleData = articleData; } @Transient public List<String> getPosidList() { List<String> list = Lists.newArrayList(); if (posid != null) { for (String s : StringUtils.split(posid, ",")) { list.add(s); } } return list; } @Transient public void setPosidList(List<Long> list) { posid = "," + StringUtils.join(list, ",") + ","; } }