There appears to be a problem when a unique key is defined on a subclass of a hierarchy.
The SchemaExportTask declares the unique key twice in the output DDL, which is not allowed.
Hibernate version: 3.0b1 (problem also occurs with 2.1.6)
Mapping documents (generated by Xdoclet):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-cascade="none" default-access="property" auto-import="true">
<class name="myproject.bean.AOwner" table="TB_OWNER_HRY" polymorphism="implicit" dynamic-update="false" dynamic-insert="false" select-before-update="false" optimistic-lock="version" mutable="true" batch-size="1">
<id name="oid" column="OID" type="java.lang.Integer" unsaved-value="null">
<generator class="identity"/>
</id>
<discriminator column="DISCRIMINATOR" type="string" length="1" not-null="true" force="false" insert="true"/>
...
<subclass name="myproject.bean.SimpleOwner" dynamic-update="false" dynamic-insert="false" discriminator-value="S">
<property name="userId" type="java.lang.String" update="true" insert="true" access="property" not-null="false" unique="false">
<column name="USER_ID" unique-key="UK_OWNER_ID" not-null="true" unique="true" sql-type="CHAR(10)"/>
</property>
</subclass>
<subclass name="myproject.bean.OwnersGroup" dynamic-update="false" dynamic-insert="false" discriminator-value="G">
...
</subclass>
</class>
</hibernate-mapping>
Ant target:
<target name="prepare">
<taskdef name="schemaexport"
classname="org.hibernate.tool.hbm2ddl.SchemaExportTask"
classpathref="class.path"/>
<schemaexport
properties="${toolz.home}/schemaexport.properties"
config="${config.home}/hibernate.cfg.xml"
quiet="no"
text="yes"
drop="no"
delimiter=";"
output="${toolz.home}/creates.sql">
</schemaexport>
</target>
Name and version of the database I am using: HSQLDB 1.7.3
The generated SQL (show_sql=true):
create table TB_OWNER_HRY (
OID integer generated by default as identity (start with 1),
DISCRIMINATOR varchar(1) not null,
NAME varchar(25) not null,
USER_ID CHAR(10) not null,
REF_GROUP integer,
primary key (OID),
unique (USER_ID), unique (USER_ID)
);
|