-->
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: Same column names for joined-subclass
PostPosted: Wed Jul 10, 2013 2:00 pm 
Newbie

Joined: Wed Jul 10, 2013 1:43 pm
Posts: 3
Have spent a few hours searching for information on this problem but no luck.

So let's say you have a base class User with a primary key column named "id". Following the table-per-subclass hierarchy, you create another class called Student with a primary key of "user_id". So "user_id" would be also be the foreign key to the "id" field of the User class. So your two database tables are set up the same with value-generation on the "id" field of User. So now you create your mapping files with the subclass in its own file. The mapping for User would now look like:
Code:
<hibernate-mapping>
    <class name="...User" table="USER" schema="..whatever">
        <id name="id" type="...Integer">
            <column name="ID" />
        </id>
        ....properties...
    </class>
</hibernate-mapping>

And your Student mapping would be:
Code:
<hibernate-mapping>
    <joined-subclass name="...User" extends="...User" table="STUDENT" schema="..whatever">
        <key column="USER_ID"/>
        ....properties...
    </joined-subclass>
</hibernate-mapping>

On save, Hibernate should be smart enough to create and insert the super-class User object first, then take the generated id from its "id" column and insert into "user_id" specified in the Student's <key> tag column. Well for some odd reason, it only works IF the two columns have the same name. In this case, in the Student mapping file, it would have to be <key column="ID">. Also, the Student table in the database also has to have the primary/foreign key column named the same as the User tables primary key, so "USER_ID" needs to be renamed to "ID". There is no documentation on this issue. Nowhere can I find something that says these columns must be named the same. I've tried multiple variations and none have worked. I keep getting "id is required to load" exceptions and I can see by the query that the insert statement for Student includes an "ID" column instead of "USER_ID".

Has anyone else experienced this issue? Anybody know anything about this? I believe this is Hibernate 3 something.


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.