SQLGrammarException: could not get or update next value...

2008-06-06 20:37
《Hiberante学习笔记》--错误篇2:
 
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not get or update next value
 
 
分析:MyEclipse自动生成的hibernate.hbm.xml中的id配置是
<id name="id" type="integer" >
   <column name="id"/>
   <generator class="hilo" />
</id>
 
由于Hilo主键生成方式采用的是hilo算法,不必要指定id的(这点和assigned类似,主键的值由hibernate维护)。但hilo算法需要额外的数据表my_unique_key和字段next_hi(这个表名和字段名是默认的,都可修改),且next_hi必须有一条记录。
 
所以,在hibernate.hbm.xml中,id的配置要写成这样:
<id name="id" type="integer" column="id">
  <generator class="hilo">
  <param name="table">my_unique_key</param>
  <param name="column">next_hi</param>
  </generator>
</id>
 
补充:
表my_unique_key的示例:
 
next_hi
20
 
即20是初始的next_hi字段的值,并且next_hi_value在表my_unique_key中设为主键。
1166 次阅读 | 0 个评论