Hi everyone,
First, thanks for Hibernate - it's a marvelous tool. Now my question. I am using
Hibernate version 3.2 and I believe I have discovered an issue with SchemaExport.
Specifically, it appears to produce duplicate columns when a collection refers to a union-subclass.
Here are two example
mapping documents. The first document describes a class Foo that refers to a class Baz (in the second mapping document) which extends (via union-subclass) a class Bar (also in the second mapping document).
Code:
<?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="p.Foo">
<id name="id" type="int" column="id"/>
<map name="bazMap" cascade="delete-orphan" lazy="false">
<key column="fooId"/>
<index column="name" type="string"/>
<one-to-many class="p.Baz"/>
</map>
</class>
</hibernate-mapping>
Code:
<?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="p.Bar" abstract="true">
<id name="id" type="int" column="id"/>
<many-to-one name="foo" column="fooId" class="p.Foo"/>
<property name="name" type="string"/>
<union-subclass name="p.Baz" table="baz"/>
</class>
</hibernate-mapping>
When I run SchemaExport against my database,
MySQL 5, it produces the following SQL statement (among others):
Code:
create table baz (id integer not null, fooId integer, name varchar(255), fooId integer, name varchar(255), primary key (id)) type=InnoDB
This causes an error because the "fooId" and "name" columns are repeated.Now, If I modify the first mapping document so that the <one-to-many> element refers to the class "p.Bar", the superclass of p.Baz, then the (valid) SQL statement that is generated looks like this.
Code:
create table baz (id integer not null, fooId integer, name varchar(255), primary key (id)) type=InnoDB
Note that the duplicates columns are gone. It's as if the fields in the p.Bar superclass are being discovered twice when the map refers to the p.Baz subclass.
Any suggestions would be greatly appreciated.
Thanks,
Jeff