WEB开发网
开发学院软件开发Java 使用SpringSide 3.1.4.3开发Web项目的全过程(上)... 阅读

使用SpringSide 3.1.4.3开发Web项目的全过程(上)

 2009-09-24 00:00:00 来源:WEB开发网   
核心提示: packagepersonal.youxia.entity;importjava.util.LinkedHashSet;importjava.util.Set;importjavax.persistence.CascadeType;importjavax.persistence.Entity;i

package personal.youxia.entity;
import java.util.LinkedHashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
@Entity
// 表名与类名不相同时重新定义表名.
@Table(name = "articles")
// 默认的缓存策略.
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Article extends IdEntity {
    private String subject;
    private String content;
    private Set<Comment> comments = new LinkedHashSet<Comment>();
    public String getSubject() {
        return subject;
    }
    public void setSubject(String subject) {
        this.subject = subject;
    }
    public String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }
    @OneToMany(cascade = { CascadeType.ALL })
    @JoinColumn(name = "article_id")
    // Fecth策略定义
    @Fetch(FetchMode.SUBSELECT)
    // 集合按id排序.
    @OrderBy("id")
    // 集合中对象id的缓存.
    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
    public Set<Comment> getComments() {
        return comments;
    }
    public void setComments(Set<Comment> comments) {
        this.comments = comments;
    }
}

上一页  2 3 4 5 6 7 8 9 10  下一页

Tags:使用 SpringSide 开发

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接