org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling


org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): ***(POJO类,及持久化类名) 

分析及解决: 

你要操作的数据表中的id(即主键)的类型设置成了“自动增长类型”,而在你的 

hibernate.cfg.xml中,id的生成方式是assigned,即 
<id name="id" type="integer"> 
            <column name="id" /> 
            <generator class="assigned" /> 
</id> 
这种搭配是矛盾的! 

主键的assigned生成方式由程序自动生成表的主键,即在你的测试程序中要调用setId()方法,且必 

须在调用save()前调用(或者说在调用save()前必须指定id,其实就是说,主键值不能为空!)。 
把主键的生成方式改为native,它的特征是能够根据底层数据库自动选择主键生成方式。

你可能感兴趣的:(org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling)