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: generator for id that has one-to-many reference
PostPosted: Wed Aug 26, 2009 11:13 am 
Newbie

Joined: Tue Aug 25, 2009 5:56 am
Posts: 4
Hi there

I have 2 tables

tblParent
parentID - primary key
description

tblChild
parentID - primary key +
childID - primary key ( composed)
description

Code:
<hibernate-mapping>
     <class name="mypackage.Parent" table="tblParent">

        <id name="parentID">
            <column name="pk_iParentID" sql-type="integer"/>
            <generator class="native"/><!-- ADDED AFTER -->
        </id>

        <property name="description">
            <column name="szDescription" not-null="false" sql-type="varchar(100)"/>
        </property>

        <set cascade="all, delete-orphan" inverse="true" name="reference2Child">
                 <key>
                    <column name="pkfk_iParentID" not-null="true"/>
                 </key>
            <one-to-many class="mypackage.Child"/>
        </set>
    </class>
</hibernate-mapping>


Code:
<hibernate-mapping>
     <class name="mypackage.Child" table="tblChild">
     
        <composite-id class="mypackage.ChildPK" mapped="true">
            <key-property name="parentID">
                <column name="pkfk_iParentID" not-null="true" sql-type="integer"/>
            </key-property>
            <key-property name="childID">
                <column name="pk_iChildID" not-null="true" sql-type="integer"/>
            </key-property>
        </composite-id>

        <property name="description">
            <column name="szDescription" not-null="false" sql-type="varchar(100)"/>
        </property>

     </class>
</hibernate-mapping>


I've lost two days trying to convince hibernate to automatically generate parentID (incremental or sequencial - not important) but it seems to be impossible.

Normally is enough to just create a new object of type Parent with parentID null and persist it in db. then hibernate will generate parentID automatically. and it works but only in case that parent hasn't children.
if object parent to be persisted has reference to children then hibernate will throw error:
"column 'pkfk_iParentID' in table 'tblChild' cannot be NULL"

More of that , i tried to add reference many-to-one from children to parent ( although i don't need it and will bring me a lack of performance) but still without success; hibernate get error from JDBC "JZ0SB: Parameter index out of range"
I don't know what to think anymore, this is a issue in hibernate's garden or i do something wrong. I red thousands post but i didn't found any helpful clue.
I'm running out of time and i tending to reach desperation.

Many thanks in advance for any advice that can give me/
Best regards
grandanat


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.