【话题讨论功能模块】话题讨论类关系【用于理解一对多等映射、级联关系】

【话题分类对应类】
package com.jspxcms.core.domain;

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

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.TableGenerator;


/**
 * The persistent class for the sc_ask_category database table.
 * 
 */
@Entity
@Table(name="sc_ask_category")
@NamedQuery(name="ScAskCategory.findAll", query="SELECT s FROM ScAskCategory s")
public class ScAskCategory implements Serializable {
	private static final long serialVersionUID = 1L;
	private Integer id;
	private String code;
	private int leaf;
	private String name;
	private Integer parentid;
	private int sort;
	private Set<ScAsk> asks = new HashSet<ScAsk>();

	public ScAskCategory() {
	}


	@Id
	@TableGenerator(name = "tg_sc_ask_category", pkColumnValue = "sc_ask_category", table = "t_id_table", pkColumnName = "f_table", valueColumnName = "f_id_value", initialValue = 1, allocationSize = 1)
	@GeneratedValue(strategy = GenerationType.TABLE, generator = "tg_sc_ask_category")
	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}


	public String getCode() {
		return this.code;
	}

	public void setCode(String code) {
		this.code = code;
	}


	public int getLeaf() {
		return this.leaf;
	}

	public void setLeaf(int leaf) {
		this.leaf = leaf;
	}


	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}


	public Integer getParentid() {
		return this.parentid;
	}

	public void setParentid(Integer parentid) {
		this.parentid = parentid;
	}


	public int getSort() {
		return this.sort;
	}

	public void setSort(int sort) {
		this.sort = sort;
	}

	@OneToMany(mappedBy="category")
	@OrderBy(value="ctime desc ")
	public Set<ScAsk> getAsks() {
		return asks;
	}


	public void setAsks(Set<ScAsk> asks) {
		this.asks = asks;
	}
	
}
  1 【问题类】
  2 package com.jspxcms.core.domain;
  3 
  4 import java.io.Serializable;
  5 import java.util.Date;
  6 import java.util.HashSet;
  7 import java.util.Set;
  8 
  9 import javax.persistence.CascadeType;
 10 import javax.persistence.Column;
 11 import javax.persistence.Entity;
 12 import javax.persistence.GeneratedValue;
 13 import javax.persistence.GenerationType;
 14 import javax.persistence.Id;
 15 import javax.persistence.JoinColumn;
 16 import javax.persistence.ManyToOne;
 17 import javax.persistence.NamedQuery;
 18 import javax.persistence.OneToMany;
 19 import javax.persistence.OneToOne;
 20 import javax.persistence.OrderBy;
 21 import javax.persistence.Table;
 22 import javax.persistence.TableGenerator;
 23 import javax.persistence.Temporal;
 24 import javax.persistence.TemporalType;
 25 
 26 import org.hibernate.annotations.LazyCollection;
 27 import org.hibernate.annotations.LazyCollectionOption;
 28 
 29 
 30 /**
 31  * The persistent class for the sc_ask database table.
 32  * 
 33  */
 34 @Entity
 35 @Table(name="sc_ask")
 36 @NamedQuery(name="ScAsk.findAll", query="SELECT s FROM ScAsk s")
 37 public class ScAsk implements Serializable {
 38     private static final long serialVersionUID = 1L;
 39     private Integer id;
 40     private ScAskCategory category;
 41     private Date ctime;
 42     private Date lasttime;
 43     private int readpop;
 44     private ScRuninfo runinfo;
 45     private ScText text;
 46     private String title;
 47     private User user;
 48     private Set<ScAskAnswer> answers = new HashSet<ScAskAnswer>();
 49     public ScAsk() {
 50     }
 51 
 52 
 53     @Id
 54     @TableGenerator(name = "tg_sc_ask", pkColumnValue = "sc_ask", table = "t_id_table", pkColumnName = "f_table", valueColumnName = "f_id_value", initialValue = 1, allocationSize = 1)
 55     @GeneratedValue(strategy = GenerationType.TABLE, generator = "tg_sc_ask")
 56     public Integer getId() {
 57         return this.id;
 58     }
 59 
 60     public void setId(Integer id) {
 61         this.id = id;
 62     }
 63 
 64 
 65     
 66 
 67     @ManyToOne
 68     @JoinColumn(name="CATEGORY_ID")
 69     public ScAskCategory getCategory() {
 70         return category;
 71     }
 72 
 73 
 74     public void setCategory(ScAskCategory category) {
 75         this.category = category;
 76     }
 77 
 78 
 79     @Temporal(TemporalType.TIMESTAMP)
 80     public Date getCtime() {
 81         return this.ctime;
 82     }
 83 
 84     public void setCtime(Date ctime) {
 85         this.ctime = ctime;
 86     }
 87 
 88 
 89     @Temporal(TemporalType.TIMESTAMP)
 90     public Date getLasttime() {
 91         return this.lasttime;
 92     }
 93 
 94     public void setLasttime(Date lasttime) {
 95         this.lasttime = lasttime;
 96     }
 97 
 98 
 99     public int getReadpop() {
100         return this.readpop;
101     }
102 
103     public void setReadpop(int readpop) {
104         this.readpop = readpop;
105     }
106 
107     @OneToOne(cascade={CascadeType.REMOVE,CascadeType.PERSIST,CascadeType.MERGE})
108     @JoinColumn(name="RUNINFO_ID")
109     public ScRuninfo getRuninfo() {
110         return runinfo;
111     }
112 
113     public void setRuninfo(ScRuninfo runinfo) {
114         this.runinfo = runinfo;
115     }
116 
117 
118     @OneToOne(cascade={CascadeType.REMOVE,CascadeType.PERSIST,CascadeType.MERGE})
119     @JoinColumn(name="TEXT_ID")
120     public ScText getText() {
121         return text;
122     }
123 
124 
125     public void setText(ScText text) {
126         this.text = text;
127     }
128 
129 
130     public String getTitle() {
131         return this.title;
132     }
133 
134     public void setTitle(String title) {
135         this.title = title;
136     }
137 
138     @OneToOne
139     @JoinColumn(name="USER_ID")
140     public User getUser() {
141         return user;
142     }
143     public void setUser(User user) {
144         this.user = user;
145     }
146 
147     @OneToMany(mappedBy="ask",cascade={CascadeType.REMOVE})
148     @LazyCollection(LazyCollectionOption.FALSE)
149     @OrderBy(value="ctime desc")
150     public Set<ScAskAnswer> getAnswers() {
151         return answers;
152     }
153 
154     public void setAnswers(Set<ScAskAnswer> answers) {
155         this.answers = answers;
156     }
157 
158     
159 }
【回复问题的答案类】
package com.jspxcms.core.domain;

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

import javax.persistence.CascadeType;
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.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;


/**
 * The persistent class for the sc_ask_answer database table.
 * 
 */
@Entity
@Table(name="sc_ask_answer")
@NamedQuery(name="ScAskAnswer.findAll", query="SELECT s FROM ScAskAnswer s")
public class ScAskAnswer implements Serializable {
    private static final long serialVersionUID = 1L;
    private Integer id;
    private ScAsk ask;
    private Date ctime;
    private Date lasttime;
    private ScText text;
    private User user;
    private Set<ScAnswerReply> replys = new HashSet<ScAnswerReply>();
    public ScAskAnswer() {
    }


    @Id
    @TableGenerator(name = "tg_sc_ask_answer", pkColumnValue = "sc_ask_answer", table = "t_id_table", pkColumnName = "f_table", valueColumnName = "f_id_value", initialValue = 1, allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.TABLE, generator = "tg_sc_ask_answer")
    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }


    
    @ManyToOne(fetch=FetchType.EAGER)
    @JoinColumn(name="ASK_ID")
    public ScAsk getAsk() {
        return ask;
    }


    public void setAsk(ScAsk ask) {
        this.ask = ask;
    }


    @Temporal(TemporalType.TIMESTAMP)
    public Date getCtime() {
        return this.ctime;
    }

    public void setCtime(Date ctime) {
        this.ctime = ctime;
    }


    @Temporal(TemporalType.TIMESTAMP)
    public Date getLasttime() {
        return this.lasttime;
    }

    public void setLasttime(Date lasttime) {
        this.lasttime = lasttime;
    }

    @OneToOne(cascade={CascadeType.REMOVE,CascadeType.MERGE})
    @JoinColumn(name="TEXT_ID")
    public ScText getText() {
        return text;
    }


    public void setText(ScText text) {
        this.text = text;
    }


    @OneToOne
    @JoinColumn(name="USER_ID")
    public User getUser() {
        return user;
    }


    public void setUser(User user) {
        this.user = user;
    }

    @OneToMany(mappedBy="answer",cascade={CascadeType.REMOVE})
    @LazyCollection(LazyCollectionOption.FALSE)
    @OrderBy(value="ctime ASC")
    public Set<ScAnswerReply> getReplys() {
        return replys;
    }


    public void setReplys(Set<ScAnswerReply> replys) {
        this.replys = replys;
    }


    
}
【回复答案的讨论类】
package com.jspxcms.core.domain;

import java.io.Serializable;
import java.util.Date;

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.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;


/**
 * The persistent class for the sc_answer_reply database table.
 * 
 */
@Entity
@Table(name="sc_answer_reply")
@NamedQuery(name="ScAnswerReply.findAll", query="SELECT s FROM ScAnswerReply s")
public class ScAnswerReply implements Serializable {
    private static final long serialVersionUID = 1L;
    private Integer id;
    private ScAskAnswer answer;
    private String content;
    private Date ctime;
    private User remaindUser;
    private User user;

    public ScAnswerReply() {
    }


    @Id
    @TableGenerator(name = "tg_sc_answer_reply", pkColumnValue = "sc_answer_reply", table = "t_id_table", pkColumnName = "f_table", valueColumnName = "f_id_value", initialValue = 1, allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.TABLE, generator = "tg_sc_answer_reply")
    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }
    

    @ManyToOne
    @JoinColumn(name="ANSWER_ID")
    public ScAskAnswer getAnswer() {
        return answer;
    }


    public void setAnswer(ScAskAnswer answer) {
        this.answer = answer;
    }


    public String getContent() {
        return this.content;
    }

    public void setContent(String content) {
        this.content = content;
    }


    @Temporal(TemporalType.TIMESTAMP)
    public Date getCtime() {
        return this.ctime;
    }

    public void setCtime(Date ctime) {
        this.ctime = ctime;
    }

    
    @OneToOne
    @JoinColumn(name="REMAINDUSER_ID")
    public User getRemaindUser() {
        return remaindUser;
    }


    public void setRemaindUser(User remaindUser) {
        this.remaindUser = remaindUser;
    }


    @OneToOne
    @JoinColumn(name="USER_ID")
    public User getUser() {
        return user;
    }


    public void setUser(User user) {
        this.user = user;
    }


}
【问题和答案的正文类】
package com.jspxcms.core.domain;

import java.io.Serializable;
import javax.persistence.*;


/**
 * The persistent class for the sc_text database table.
 * 
 */
@Entity
@Table(name="sc_text")
@NamedQuery(name="ScText.findAll", query="SELECT s FROM ScText s")
public class ScText implements Serializable {
    private static final long serialVersionUID = 1L;
    private Integer id;
    private String text;

    public ScText() {
    }


    @Id
    @TableGenerator(name = "tg_sc_text", pkColumnValue = "sc_text", table = "t_id_table", pkColumnName = "f_table", valueColumnName = "f_id_value", initialValue = 1, allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.TABLE, generator = "tg_sc_text")
    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }


    @Lob
    public String getText() {
        return this.text;
    }

    public void setText(String text) {
        this.text = text;
    }

}
【针对问题的 浏览数  回复数  讨论数的类】
package com.jspxcms.core.domain;

import java.io.Serializable;

import javax.persistence.*;


/**
 * The persistent class for the sc_runinfo database table.
 * 
 */
@Entity
@Table(name="sc_runinfo")
@NamedQuery(name="ScRuninfo.findAll", query="SELECT s FROM ScRuninfo s")
public class ScRuninfo implements Serializable {
    private static final long serialVersionUID = 1L;
    private Integer id;
    private Integer answeringnum;
    private Integer replynum;
    private Integer visitnum;

    public ScRuninfo() {
    }


    @Id
    @TableGenerator(name = "tg_sc_runinfo", pkColumnValue = "sc_runinfo", table = "t_id_table", pkColumnName = "f_table", valueColumnName = "f_id_value", initialValue = 1, allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.TABLE, generator = "tg_sc_runinfo")
    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Column(name = "answeringnum")
    public Integer getAnsweringnum() {
        return answeringnum;
    }


    public void setAnsweringnum(Integer answeringnum) {
        this.answeringnum = answeringnum;
    }

    @Column(name = "replynum")
    public Integer getReplynum() {
        return replynum;
    }


    public void setReplynum(Integer replynum) {
        this.replynum = replynum;
    }

    @Column(name = "visitnum")
    public Integer getVisitnum() {
        return visitnum;
    }


    public void setVisitnum(Integer visitnum) {
        this.visitnum = visitnum;
    }


}

【六个类对应数据库表如下】

问题分类对应表

问题表

【答案表】

【讨论表】

【正文表】

【浏览数 回复数 讨论数表】

 

 

 

 

 

 

 

 

 

  

posted @ 2016-08-23 16:57  涤新云  阅读(367)  评论(0编辑  收藏  举报