-->
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.  [ 4 posts ] 
Author Message
 Post subject: joined-subclass and IDENTITY_INSERT
PostPosted: Mon Jul 19, 2004 4:49 am 
Newbie

Joined: Wed Jun 16, 2004 8:26 am
Posts: 19
Hi all,

i try to insert into a joined-subclass table on MS-SQL-Server with identifiers of type 'identity' .

Mapping
Code:
<hibernate-mapping>
    <class name="com.tecdoc.db_update.hibernate.Bean_Update_Installation"
        table="t_Update_Installation">
        <id unsaved-value="0" name="idInstall" column="idInstall"
            type="integer">
            <generator class="identity">
            </generator>
        </id>
        <property name="installDatum" column="installDatum"
            type="java.lang.String"/>
        <property name="installVon" column="installVon"
            type="java.lang.String"/>
        <property name="installBemerkung" column="installBemerkung"
            type="java.lang.String"/>
        <many-to-one name="teilUpdate"
            class="com.tecdoc.db_update.hibernate.Bean_Update" not-null="true"/>

    <joined-subclass name="com.tecdoc.db_update.hibernate.Bean_Datenbank"
        table="t_Datenbank">
        <key column="idDb"/>
        <many-to-one name="server"
            class="com.tecdoc.db_update.hibernate.Bean_Server" not-null="true"/>
        <many-to-one name="sid" class="com.tecdoc.db_update.hibernate.Bean_SID"
            not-null="true"/>
    </joined-subclass>

    <joined-subclass         name="com.tecdoc.db_update.hibernate.Bean_Applikation"
        table="t_Applikation">
        <key column="idApplikation"/>
        <many-to-one name="app"
            class="com.tecdoc.db_update.hibernate.Bean_App"
            not-null="true"/>
    </joined-subclass>
    </class>

</hibernate-mapping>


when i call saveOrUpdate i get the following error:
[code]
Caused by: java.sql.SQLException: Ein expliziter Wert f

_________________
Have Fun!

Torsten


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 19, 2004 4:53 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
the key column of a joined-subclass table can not be autogenerated by the database, which is quite clear if you think about it. Only the main class table id may be autogenerated.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 19, 2004 4:59 am 
Newbie

Joined: Wed Jun 16, 2004 8:26 am
Posts: 19
Thanks i forgot to change this to the create_table-script of my DB.

_________________
Have Fun!

Torsten


Top
 Profile  
 
 Post subject: Question regarding table-per-subclass and primary keys
PostPosted: Thu Nov 04, 2004 1:25 am 
Newbie

Joined: Thu Nov 04, 2004 12:52 am
Posts: 4
Given an object hierarchy where ThirdObject extends SecondObject which extends FirstObject, is the following schema for a table-per-subclass hierarchy ok?


Table 1
Code:
FirstObjects
------------
firstObjectId (PK, IDENTITY)
propertyOfFirstObject


Table 2
Code:
SecondObjects
-------------
secondObjectId (PK, IDENTITY)
firstObjectId (FK)
propertyOfSecondObject


Table 3
Code:
ThirdObjects
------------
thirdObjectId (PK, IDENTITY)
secondObjectId (FK)
propertyOfThirdObject


The table for each subclass has its own primary key which is an MS SQL Server IDENTITY column. Further, each subclass's table has a FK column which relates to the PK column of the parent class's table (FK secondObjectId in table ThirdObjects relates to PK secondObjectId in table SecondObjects, and so on). So again, is this schema correct for table-per-subclass hierarchy?

Second question, with regards to the PK columns in each subclass table, should they be included in the mapping for each subclass or not? Is the following mapping correct?


Code:
<class name="FirstObject" table="FirstObjects">
    <id name="firstObjectId" type="long">
        <generator class="native"/>
    </id>
    <property name="propertyOfFirstObject"/>
    <joined-subclass name="SecondObject" table="SecondObjects">
        <key column="firstObjectId"/>
        <property name="propertyOfSecondObject"/>
        <joined-subclass name="ThirdObject" table="ThirdObjects">
            <key column="secondObjectId"/>
            <property name="propertyOfThirdObject"/>
        </joined-subclass>
    </joined-subclass>
</class>


Is it correct that the PK columns for the subclasses are omitted from the mapping document entirely? Should they be in there with insert="false" and update="false"? Should they be in there as ids as with the parent class?

Hope the above was clear. Thanks, greatly, in advance, and kudos on a phenomenal tool!

Brian St.Clair


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

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.