因为
mysql我建议您以下:
在表
messages的字段中
id添加声明
auto_increment:
create table messages(...id int not null auto_increment,...primary key (id))
在实体声明时使用
@Id@GeneratedValue(strategy = GenerationType.IDENTITY)private int id;
这谈到了JPA使用MySQL的自动增量功能
如果不适用(例如,您可能想在同一事务中创建相关的另一个实体),请使用TABLE策略(有关更多详细信息,请参见http://www.objectdb.com/java/jpa/entity/generation)



