-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Map of subclasses keyed by property of superclass fails
PostPosted: Fri Jun 18, 2004 8:57 am 
Newbie

Joined: Fri Apr 23, 2004 4:18 pm
Posts: 15
Location: Oslo, Norway
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)
);


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.