My simplified domain model consists of tree classes: TreeNode, IndustryNode inheriting the TreeNode, and Enterprise. And their relationships are modeled as many-to-many between IndustryNode and Enterprise, joined-subclass between TreeNode and IndustryNode.
And the mapping file is
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="domain.common.tree.TreeNode"
table="QBS_TREENODE"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="objID"
column="TREENODE_OBJID"
type="java.lang.String"
length="32"
>
<generator class="uuid.hex">
</generator>
</id>
<property
name="nodeData"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="TN_DATA"
length="256"
/>
</property>
<many-to-one
name="parentNode"
class="domain.common.tree.TreeNode"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="FK_TN_PARENT_ID"
/>
<many-to-one
name="tree"
class="domain.common.tree.Tree"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="FK_TREE_ID"
/>
<joined-subclass
name="domain.enterprise.industry.IndustryNode"
table="QBS_TREENODE_INDUSTRY"
dynamic-update="false"
dynamic-insert="false"
>
<key
column="TN_OBJID"
/>
<property
name="industryName"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="IN_NAME"
length="128"
/>
</property>
<property
name="industryCode"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="IN_CODE"
length="128"
/>
</property>
<bag
name="enterprises"
table="QBS_JOIN_ENTERPRISE_INDUSTRYNODE"
lazy="true"
inverse="false"
cascade="delete"
>
<key
column="TN_OBJID"
/>
<many-to-many
class="domain.enterprise.Enterprise"
column="FK_ENTER_ID"
outer-join="auto"
/>
</bag>
</joined-subclass>
</class>
<class
name="domain.enterprise.Enterprise"
table="QBS_ENTERPRISE"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="objID"
column="ENTER_OBJID"
type="java.lang.String"
length="32"
>
<generator class="uuid.hex">
</generator>
</id>
<property
name="enterName"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="ENTER_NAME"
length="128"
not-null="true"
/>
</property>
<bag
name="industries"
table="QBS_JOIN_ENTERPRISE_INDUSTRYNODE"
lazy="true"
inverse="false"
cascade="delete"
>
<key
column="FK_ENTER_ID"
/>
<many-to-many
class="domain.enterprise.industry.IndustryNode"
column="TN_OBJID"
outer-join="auto"
/>
</bag>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Enterprise.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>
The DDL exported is
Quote:
14:21:35,579 DEBUG SchemaExport:149 - create table QBS_ENTERPRISE (
ENTER_OBJID VARCHAR(32) not null,
ENTER_NAME VARCHAR(128) not null,
primary key (ENTER_OBJID)
)
14:21:35,599 DEBUG SchemaExport:149 - create table QBS_JOIN_ENTERPRISE_INDUSTRYNODE (
FK_ENTER_ID VARCHAR(32) not null,
TN_OBJID VARCHAR(255) not null
)
14:21:35,900 DEBUG SchemaExport:149 - create table QBS_TREENODE_INDUSTRY (
TN_OBJID VARCHAR(32) not null,
IN_NAME VARCHAR(128) null,
IN_CODE VARCHAR(128) null,
primary key (TN_OBJID)
)
14:21:38,664 DEBUG SchemaExport:149 - create table QBS_TREENODE (
TREENODE_OBJID VARCHAR(32) not null,
TN_DATA VARCHAR(256) null,
FK_TN_PARENT_ID VARCHAR(32) null,
primary key (TREENODE_OBJID)
)
So I got errors when creating the constraint as:
Quote:
14:21:38,974 ERROR SchemaExport:154 - Unsuccessful: alter table QBS_JOIN_ENTERPRISE_INDUSTRYNODE add constraint FK78568BA6DA9D8A2D foreign key (TN_OBJID) references QBS_TREENODE_INDUSTRY
The Schema Export creates the column TN_OBJID of the joined table with 255 rather the length of the indentifer of IndustryNode. Do you guys think it is a bug? or Is there something wrong?
Regards,
James.