【发布时间】:2011-06-07 01:07:54
【问题描述】:
我有一个帖子类,它有点工作,但有一个问题:主键没有增加。
@Entity
@Table(name="posts")
public class Post extends GenericModel{
@Id
@Column(name="post_id")
public int id;
@Column(name="post_situation")
public String situation;
@Column(name="post_date")
public Date date;
@Column(name="post_userid")
public int userid;
@OneToMany(mappedBy="post", cascade=CascadeType.ALL)
public List<Block> blocks;
public Post addBlock(String content, int position){
Block b = new Block(this, content, position);
b.save();
this.blocks.add(b);
this.save();
return this;
}
public Post(String situation, Date date){
this.situation = situation;
this.date = date;
this.userid = 2;
}
}
当我第一次在空桌子上调用它时,它工作正常,但第二次,我得到PersistenceException occured : org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
post_id 列始终为 0。知道如何解决这个问题吗?我有 @Id 注释。
这就是我在控制器中的方式:
Post p = new Post("Midden in het middenoosten.", new Date()).save();
任何想法是什么导致了这个问题?
【问题讨论】:
标签: java jpa primary-key playframework