Problemdescription: Schemageneration (wrongly?) enforces a property declared on a superclass on a subclass when the subclass i used in a map keyed on the superclasses parent (pheew!).
Look below for example mapping that fails.
Why does schema generation add the
name column to UglyCat?
If I create an UglyCat and save it, all look fine (name gets saved on row in the Cat table). When I then try to add it to the map of uglyCats on Owner, Hibernate complaints about name beeing null. It seems to (wrongly? look for name on the UglyCat.
Any thoughts?
Example:
Mapping file for Cat and UglyCat:
Code:
<hibernate-mapping>
<class name="com.Cat" table="cat">
<id name="id" type="string" length="32">
<generator class="uuid.hex"/>
</id>
<property name="name" type="string" not-null="true"/>
<joined-subclass name="com.UglyCat" table="uglyCat">
<key column="cat"/>
<many-to-one name="owner" column="ownerId" not-null="true" class="com.Owner"/>
</joined-subclass>
</class>
</hibernate-mapping>
Mapping file for Owner:
Code:
<hibernate-mapping>
<class name="com.Owner" table="owner">
<id name="id" type="string" length="32">
<generator class="uuid.hex"/>
</id>
<map name="uglyCats" inverse="true" cascade="all-delete-orphan" lazy="false">
<key column="ownerId"/>
<index column="name" type="string"/>
<one-to-many class="com.UglyCat"/>
</map>
</class>
</hibernate-mapping>
Schema generated (for Oracle9):
Code:
create table cat (
id VARCHAR2(32) not null,
name VARCHAR2(255) not null,
primary key (id)
);
create table owner (
id VARCHAR2(32) not null,
primary key (id)
);
create table uglyCat (
cat VARCHAR2(32) not null,
ownerId VARCHAR2(32) not null,
name VARCHAR2(255),
primary key (cat)
);