如何建模这个domain模型

需求:
这个留言版的模型,一个user可以有多个留言和回复,  一个留言可以对应多个回复,   删除留言时同时删除留言:

package com.easyjweb.demo.domain;

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

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.sql.Delete;

import com.easyjf.container.annonation.Field;
import com.easyjf.container.annonation.FormPO;
import com.easyjf.container.annonation.Validator;

/**
* Message
*
* @author EasyJweb $$Id: Account.java,v 0.0.1 2007-8-24 15:09:43 EasyJweb code
*         Generate Engine 0.0.1 Exp $
*/

@Entity
@FormPO(name = "Message", inject = "title,content,vdate,parent", disRead = "ip")
public class Message implements Serializable {

@Field(gener = false)
/**
* 指定是否在页面生成
*
* @return 若该属性不需要在前台页面中生存,则返回false,否则返回true,默认值为true
*/
private static final long serialVersionUID = 52257160592323648L;

@Id
@GeneratedValue(strategy = GenerationType.TABLE)
private Long id;

@Lob
@Field(name = "留言内容", validator = @Validator(name = "string", value = "blank;trim", required = true))
private String content;

@Temporal(TemporalType.DATE)
private Date vdate;

private String ip;

// 表示回复时引用的主贴。
@ManyToOne(cascade = CascadeType.ALL)
private Message parent;

@ManyToOne(cascade =CascadeType.ALL)
private User user;

public String getContent() {
return content;
}

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

public Long getId() {
return id;
}

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

public Message getParent() {
return parent;
}

public void setParent(Message parent) {
this.parent = parent;
}

public Date getVdate() {
return vdate;
}

public void setVdate(Date vdate) {
this.vdate = vdate;
}

public String getIp() {
return ip;
}

public void setIp(String ip) {
this.ip = ip;
}

public User getUser() {
return user;
}

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

}

你可能感兴趣的:(sql,Hibernate)