各位大佬们好:
       我在用s2sh集成做一个bbs论坛系统时,在提交一个帖子时,出现了
???? NULL ??? 'post_id'?? 'bbs.dbo.bbs_message'?????????INSERT ??? 
freeer.template.TemplateModelException: Method public java.lang.String org.hibernate.exception.NestableRuntimeException.getMessage(int) threw an exception when invoked on org.hibernate.exception.ConstraintViolationException: could not insert: [com.bbs.entity.BbsMessage]
问题。
post_id为复合主键类BbsMessageId的字段,
BbsMessageId如下:
package com.bbs.entity;import javax.persistence.Column;
import javax.persistence.Embeddable;/**
 * BbsMessageId entity. @author MyEclipse Persistence Tools
 */
@Embeddable
public class BbsMessageId implements java.io.Serializable { // Fields private String postId;
private String authorId; // Constructors /** default constructor */
public BbsMessageId() {
} /** full constructor */
public BbsMessageId(String postId, String authorId) {
this.postId = postId;
this.authorId = authorId;
} // Property accessors @Column(name = "post_id", nullable = false, length = 32)
public String getPostId() {
return this.postId;
} public void setPostId(String postId) {
this.postId = postId;
} @Column(name = "author_id", nullable = false, length = 32)
public String getAuthorId() {
return this.authorId;
} public void setAuthorId(String authorId) {
this.authorId = authorId;
} public boolean equals(Object other) {
if ((this == other))
return true;
if ((other == null))
return false;
if (!(other instanceof BbsMessageId))
return false;
BbsMessageId castOther = (BbsMessageId) other; return ((this.getPostId() == castOther.getPostId()) || (this
.getPostId() != null
&& castOther.getPostId() != null && this.getPostId().equals(
castOther.getPostId())))
&& ((this.getAuthorId() == castOther.getAuthorId()) || (this
.getAuthorId() != null
&& castOther.getAuthorId() != null && this
.getAuthorId().equals(castOther.getAuthorId())));
} public int hashCode() {
int result = 17; result = 37 * result
+ (getPostId() == null ? 0 : this.getPostId().hashCode());
result = 37 * result
+ (getAuthorId() == null ? 0 : this.getAuthorId().hashCode());
return result;
}}
 BbsMessage类如下:package com.bbs.entity;import java.util.HashSet;
import java.util.Set;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;/**
 * BbsMessage entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "bbs_message", schema = "dbo", catalog = "bbs")
public class BbsMessage implements java.io.Serializable { // Fields private BbsMessageId id;
private BbsUser bbsUser;
private String postContent;
private String createDate;
private String postSubject;
private String checkedPost;
private String topPostDate;
private String topPost;
private String PSort1;
private String PSort2;
private String PType;
private String denailed;
private String denailDate;
private Set<BbsWriteBack> bbsWriteBacks = new HashSet<BbsWriteBack>(0); // Constructors /** default constructor */
public BbsMessage() {
} /** minimal constructor */
public BbsMessage(BbsMessageId id, BbsUser bbsUser) {
this.id = id;
this.bbsUser = bbsUser;
} /** full constructor */
public BbsMessage(BbsMessageId id, BbsUser bbsUser, String postContent,
String createDate, String postSubject, String checkedPost,
String topPostDate, String topPost, String PSort1, String PSort2,
String PType, String denailed, String denailDate,
Set<BbsWriteBack> bbsWriteBacks) {
this.id = id;
this.bbsUser = bbsUser;
this.postContent = postContent;
this.createDate = createDate;
this.postSubject = postSubject;
this.checkedPost = checkedPost;
this.topPostDate = topPostDate;
this.topPost = topPost;
this.PSort1 = PSort1;
this.PSort2 = PSort2;
this.PType = PType;
this.denailed = denailed;
this.denailDate = denailDate;
this.bbsWriteBacks = bbsWriteBacks;
} // Property accessors
@EmbeddedId
@AttributeOverrides( {
@AttributeOverride(name = "postId", column = @Column(name = "post_id", nullable = false, length = 32)),
@AttributeOverride(name = "authorId", column = @Column(name = "author_id", nullable = false, length = 32)) })
public BbsMessageId getId() {
return this.id;
} public void setId(BbsMessageId id) {
this.id = id;
} @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "author_id", nullable = false, insertable = false, updatable = false)
public BbsUser getBbsUser() {
return this.bbsUser;
} public void setBbsUser(BbsUser bbsUser) {
this.bbsUser = bbsUser;
} @Column(name = "post_content")
public String getPostContent() {
return this.postContent;
} public void setPostContent(String postContent) {
this.postContent = postContent;
} @Column(name = "create_date", length = 30)
public String getCreateDate() {
return this.createDate;
} public void setCreateDate(String createDate) {
this.createDate = createDate;
} @Column(name = "post_subject", length = 50)
public String getPostSubject() {
return this.postSubject;
} public void setPostSubject(String postSubject) {
this.postSubject = postSubject;
} @Column(name = "checkedPost", length = 50)
public String getCheckedPost() {
return this.checkedPost;
} public void setCheckedPost(String checkedPost) {
this.checkedPost = checkedPost;
} @Column(name = "topPost_date", length = 30)
public String getTopPostDate() {
return this.topPostDate;
} public void setTopPostDate(String topPostDate) {
this.topPostDate = topPostDate;
} @Column(name = "topPost", length = 10)
public String getTopPost() {
return this.topPost;
} public void setTopPost(String topPost) {
this.topPost = topPost;
} @Column(name = "P_Sort1", length = 20)
public String getPSort1() {
return this.PSort1;
} public void setPSort1(String PSort1) {
this.PSort1 = PSort1;
} @Column(name = "P_Sort2", length = 20)
public String getPSort2() {
return this.PSort2;
} public void setPSort2(String PSort2) {
this.PSort2 = PSort2;
} @Column(name = "P_Type", length = 20)
public String getPType() {
return this.PType;
} public void setPType(String PType) {
this.PType = PType;
} @Column(name = "denailed", length = 50)
public String getDenailed() {
return this.denailed;
} public void setDenailed(String denailed) {
this.denailed = denailed;
} @Column(name = "denail_date", length = 30)
public String getDenailDate() {
return this.denailDate;
} public void setDenailDate(String denailDate) {
this.denailDate = denailDate;
} @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "bbsMessage")
public Set<BbsWriteBack> getBbsWriteBacks() {
return this.bbsWriteBacks;
} public void setBbsWriteBacks(Set<BbsWriteBack> bbsWriteBacks) {
this.bbsWriteBacks = bbsWriteBacks;
}}我就是不知道怎么为postId设置uuid生成策略,导致它为空.
请各位大哥不吝赐教.小弟是新手,在这谢谢啦!