当前位置: 代码迷 >> J2EE >> 100分解决错误异常:org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling s
  详细解决方案

100分解决错误异常:org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling s

热度:120   发布时间:2016-04-22 02:22:57.0
100分解决异常错误:org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling s
sql   server2000数据库:   table:ware   有一个   主键wid   自增

hibernatepe配置文件:
<class   name= "com.ll.model.Ware "   table= "ware "   schema= "dbo "   catalog= "vod ">
                <id   name= "wid "   type= "java.lang.Integer ">
                        <column   name= "wid "   />
                        <generator   class= "assigned "   />
                </id>

报错:org.hibernate.id.IdentifierGenerationException:   ids   for   this   class   must   be   manually   assigned   before   calling   save()

将assigned改成increment类型

报错:org.hibernate.exception.SQLGrammarException:   could   not   fetch   initial   value   for   increment   generator

Caused   by:   java.sql.SQLException:   [Microsoft][SQLServer   2000   Driver   for   JDBC][SQLServer]对象名   'ware '   无效。

将assigned改成vipId类型

报错:org.hibernate.MappingException:   could   not   instantiate   id   generator
org.hibernate.MappingException:   Could   not   read   mappings   from   resource:   com/ll/model/Admin.hbm.xml
java.lang.NullPointerException

谁来救救我!

------解决方案--------------------
generator class= "assigned“而你的类型type= "java.lang.Integer”这不明显的问题吗? 如果你的主键时自动增长的Int型,把你的assigned改成自动增长的Identity,assigned是自动增长的varchar型的。晕!
  相关解决方案