我在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) 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);
如上所示,当UNQ_BASE_INFO_PARENT_CODE
列不为空时,我在表APP_BASEINFORMATION
上创建CODE
唯一约束。我如何在.hbm.xml
?
这些是APP_BASEINFORNATION
:
<?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>
我的意思是我应该将(CASE WHEN CODE IS NOT NULL THEN PARENTID || '-' || CODE END)
放在hbm文件中以及正确的语法是什么?