我正在尝试映射我的域对象以使用新的 Oracle 12c 身份类型主键,也就是其他一些系统中的自动增量。
Hibernate 4没有Oracle12cDialect,它只有Oracle10gDialect。
Oracle10gDialect 有一个名为 supportsIdentityColumns() 的方法,该方法被硬编码为返回 false,因此将我的 GORM 域对象映射到 generator:"identity" 会导致错误,指出 Oracle10gDialect 不支持身份生成器。
我不能使用 GORM 选择生成器,因为我没有辅助唯一键,并且我不能使用 Hibernate 生成的键,因为 Hibernate 和其他(外部)插入到表中会生成重叠键。
现有 Oracle 12c DDL 示例:
create table person (
id number(10,0) generated by default as identity,
version number(10,0) not null,
home_address_id number(10,0),
name varchar(255) not null,
primary key (id)
);
GORM 对象:
class Person {
String name
Address homeAddress
static mapping = {
id column: 'person_key', generator: 'identity'
}
static constraints = {
homeAddress nullable: true
}
}
在内存数据库结果中(完美运行):
Hibernate: create table person (person_key bigint generated by default as identity, version bigint not null, home_address_id bigint, name varchar(255) not null, primary key (person_key))
Hibernate: alter table person add constraint FK_bemy93e8a8i6nknj4n21m6fub foreign key (home_address_id) references address
Hibernate: insert into person (person_key, version, home_address_id, name) values (null, ?, ?, ?)
Oracle 数据库结果(损坏):
org.hibernate.MappingException: org.hibernate.dialect.Oracle10gDialect does not support identity key generation
如何让 Grails 3.0.9 与上述 Oracle 表定义一起使用?