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;
在目標數據庫中建立對應的序列后程序可正常運行。