Hibernate Apache Derby Custom Sequence
I am trying to investigate the generator class in the ID sequence generation of Hibernate.
I tried to use the sequence generator on a very simple mapping
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping 开发者_开发知识库package="com.test">
<class name="Customer" table="Customer">
<id name="id" column="ID" type="long">
<generator class="sequence">
<param name="sequence">CUSTOMER_SEQUENCE</param>
</generator>
</id>
<property name="name" type="string" column="CUSTOMER_NAME" />
</class>
</hibernate-mapping>
I am using apache derby, the ID column in the customer table is justa simple long datatype.
But when I try to execute a simple save, I am encountering below error.
Caused by: java.sql.SQLSyntaxErrorException: SEQUENCE 'CUSTOMER_SEQUENCE' does not exist. Does this mean that Apache Derby does not support Sequence Generation? Thanks
It seems that Derby doesn't support sequence generation. Quote from official Derby FAQ:
Derby supports generated "identity" columns; examples are in the Reference Guide. The IDENTITY_VAL_LOCAL function returns the most recently assigned number.
Work is underway to add SEQUENCE support to Derby 10.6.
Derby now supports sequence generation, as follows:
http://db.apache.org/derby/docs/10.8/ref/rrefsqljcreatesequence.html
精彩评论