"HIBERNATE_SEQUENCE" does not exist问题处理

JavaWeb应用在MySQL环境下可以正常运行,数据迁移至Oracle或者人大金仓后应用运行爆出如下错误:

严重: Servlet.service() for servlet [JeeCmsAdmin] in context with path [/dhccms] threw exception [org.hibernate.exception.SQLGrammarException: could not get next sequence value] with root cause
com.kingbase8.util.KSQLException: ERROR: relation "HIBERNATE_SEQUENCE" does not exist

经查证,Hibernate中的实体类使用native方式生成主键,native是由Hibernate根据使用的数据库自行判断采用identity、hilo、sequence其中一种作为主键生成方式。

MySQL采用自增作为主键,而Oracle数据库没有类似的自增类型,因此需要一个名称为hibernate_sequence的序列做支持。

hibernate_sequence序列语句:

create sequence HIBERNATE_SEQUENCE
minvalue 100000
maxvalue 999999999999999999999999
start with 100060
increment by 1
cache 20;

在目标数据库中建立对应的序列后程序可正常运行。

原文地址:https://www.cnblogs.com/xusweeter/p/9657274.html