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"/>