Oracle 如何使用hibernate映射文件在可空列上创建条件唯一约束?
我在oracle数据库中有以下表:Oracle 如何使用hibernate映射文件在可空列上创建条件唯一约束?,oracle,hibernate,conditional,nullable,unique-constraint,Oracle,Hibernate,Conditional,Nullable,Unique Constraint,我在oracle数据库中有以下表: create table APP_BASEINFORMATIONHEADER ( id NUMBER(10) not null, topic VARCHAR2(50 CHAR) not null, subsystem_type NUMBER(10) ); create table APP_BASEINFORMATION ( id NUMBER(10)
create table APP_BASEINFORMATIONHEADER
(
id NUMBER(10) not null,
topic VARCHAR2(50 CHAR) not null,
subsystem_type NUMBER(10)
);
create table APP_BASEINFORMATION
(
id NUMBER(10) not null,
code NUMBER(10),
parentid NUMBER(10)
);
alter table APP_BASEINFORMATION
add constraint FK_BASE_INFO_PARENT foreign key (PARENTID)
references APP_BASEINFORMATIONHEADER (ID);
CREATE UNIQUE INDEX UNQ_BASE_INFO_PARENT_CODE
ON APP_BASEINFORMATION
(CASE WHEN CODE IS NOT NULL THEN PARENTID || '-' || CODE END);
如上所述,当code
列不为空时,我在表APP\u BASEINFORMATION
上创建UNQ\u BASE\u INFO\u PARENT\u code
唯一约束。如何在.hbm.xml
上设置这些条件
这是APP\u baseinformation
的hibernate映射文件:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="org.my.framework.model.core.baseInfo.BaseInformation" table="App_BaseInformation">
<id name="id" type="int" >
<column name="ID" />
<generator class="sequence" >
<param name="sequence">SEQ_BaseInformation</param>
</generator>
</id>
<property column="Code" name="code" not-null="false" type="integer" unique-key="??" />
<property column="Topic" name="topic" not-null="true" type="string" length="100"/>
<many-to-one entity-name="org.my.framework.model.core.baseInfo.BaseInformationHeader" name="parent" unique-key="??" >
<column name="ParentId" not-null="false" />
</many-to-one>
</class>
</hibernate-mapping>
SEQ_基本信息
我的意思是我应该在hbm文件中放置(如果code不为NULL,那么PARENTID | |'-'| | | code END)
,正确的语法是什么