当我尝试使用"从实体"生成表时从实体创建表时,它会创建表,但不会将属性auto_increment
添加到主键。
以下是一个示例实体:
@Entity
public class Post implements java.io.Serializable {
private static final long serialVersionUID = -665356579933050521L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long postID;
@ManyToOne(optional=false)
@JoinColumn(name = "postOwnerID", referencedColumnName = "userID", insertable = false, updatable = false)
private UserCredential postOwner;
@ManyToOne(optional=false)
@JoinColumn(name="postType", referencedColumnName="postType", nullable=false)
private PostTypeEnum postType;
@ManyToOne(optional=true)
@JoinColumn(name="postEvent", referencedColumnName="eventID", nullable=true)
private Event postEvent;
@Column(nullable=false)
@Embedded
private AuditTrail auditTrail;
@OneToMany(cascade=CascadeType.ALL)
private Set<Message> postMessages;
public Post(){
}
}
更新 我尝试使用alter table sql query更改表格帖子,我发现以下错误:
ERROR 1833 (HY000): Cannot change column 'POSTID': used in a foreign key constraint 'FK_POSTRECIPIENT_postID' of table 'class_register.postrecipient'