休眠Apache Derby自定义序列 [英] Hibernate Apache Derby Custom Sequence

查看:197
本文介绍了休眠Apache Derby自定义序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我试图在一个非常简单的映射中使用序列生成器。

我试图在Hibernate的ID序列生成中研究生成器类。

 <?xml version =1.0encoding =UTF-8?> 
<!DOCTYPE hibernate-mapping PUBLIC
- // Hibernate / Hibernate映射DTD 3.0 // EN
http://hibernate.sourceforge.net/hibernate-mapping-3.0 .dtd>
< hibernate-mapping package =com.test>
< class name =Customertable =Customer>
< id name =idcolumn =IDtype =long>
< generator class =sequence>
< param name =sequence> CUSTOMER_SEQUENCE< / param>
< / generator>
< / id>
< property name =nametype =stringcolumn =CUSTOMER_NAME/>
< / class>
< / hibernate-mapping>

我使用的是Apache Derby,客户表中的ID列只是一个简单的长数据类型。 p>

但是当我尝试执行一个简单的保存时,我遇到了下面的错误。



引起:java.sql .SQLSyntaxErrorException:SEQUENCE'CUSTOMER_SEQUENCE'不存在。
这是否意味着Apache Derby不支持序列生成?谢谢

解决方案

似乎Derby不支持序列生成。从官方德比常见问题解答中引用:


Derby支持生成的标识
列;示例在参考
指南中。 IDENTITY_VAL_LOCAL函数
返回最近分配的
数字。



工作正在为SEQUENCE
支持添加到Derby 10.6。 p>


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.

这篇关于休眠Apache Derby自定义序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆