Hibernate如何与Firebird数据库自增字段映射

Firebird 本身是没有自增型字段,但可以通过序列键产生器和触发器共同来实现,步骤如下:

CREATE TABLE my_table (
    my_number integer not null primary key
)

CREATE GENERATOR my_generator

CREATE TRIGGER my_before_trigger FOR my_table
    BEFORE INSERT
    AS
    BEGIN
    IF (NEW.my_number IS NULL) 
        THEN NEW.my_number = GEN_ID(my_generator, 1);
    END

Hibernate 与它只要用 increment 与该字段映射:

<generator class="increment"/>

类别: Hibernate. 标签: , . 阅读(189). 订阅评论. TrackBack.

Leave a Reply

Be the First to Comment!

avatar
wpDiscuz