-->
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: constrained one-to-one mapping problem
PostPosted: Sat Apr 07, 2007 5:42 pm 
Newbie

Joined: Mon Oct 16, 2006 4:19 pm
Posts: 4
I'm using hibernate 3.1 cr2

I'm using a one-to-one mapping where the 'child' table has a PK which is also a FK to the 'parent' table. So I have a constrained one-to-one mapping. The 'child' table has an id that looks like:

Code:
<id name="id" column="ad_id" type="long">
    <generator class="foreign">
          <param name="property">placement</param>
    </generator>
</id>
      
<one-to-one name="placement" class="PlacementImpl" constrained="true" />


Everything works fine for inserts and deletes, but fails on updates. Updates fail because Hibernate tries to insert into the 'child' table again instead of knowing to update. I don't know how to tell Hibernate that an update is occurring instead of an insert.

What do I need to do to get updates to work? Thanks in advance...

The two simplified mapping file are below:

Placement.hbm.xml
Code:
<class name="PlacementImpl" table="PLACEMENTS" dynamic-update="true">

    <id name="id" column="ID" unsaved-value="-1" type="long">
        <generator class="sequence">
            <param name="sequence">PLACEMENTS_SEQ</param>
        </generator>
    </id>

    <one-to-one name="userListExpression" class="UserListExpressionImpl" access="field" cascade="all" />
</class>


UserListExpression.hbm.xml
Code:
<class name="UserListExpressionImpl" table="placement_filter_expression">

    <id name="id" column="ad_id" type="long">
        <generator class="foreign">
            <param name="property">placement</param>
        </generator>
    </id>
      
    <one-to-one name="placement" class="PlacementImpl" constrained="true" />
</class>


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.