-->
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: Primary Key mapping using generated=assigned and foreign
PostPosted: Fri Apr 14, 2006 10:50 am 
Newbie

Joined: Fri Apr 14, 2006 10:16 am
Posts: 3
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hi,

I've seen similar posts on this but an unable to get my own code to work. I'm having a problem with a primary key association. In the documentation I found that "if you want two objects to be related by a primary key association, you must make sure that they are assigned the same identifier value!".

The ContentTitle primary key is assigned. It will contain a CableLabSpec instance that is to be persisted with the id of ContentTitle. I'm using the example mapping from the Hibernate 3.1.2 reference manual, Person and Employee example.

Hibernate version: 3.1.2

Mapping documents:

<class name="ContentTitle"
table="ContentTitle"
schema="dbo"
catalog="myVOD">

<id name="id"
type="int"
column="contentID">
<generator class="assigned"/>
</id>

<one-to-one name="cableLabSpec"
class="CableLabSpec"
cascade="all"
constrained="false"/>

............

<class name="CableLabSpec" table="CableLabSpec" schema="dbo" catalog="myVOD">
<id name="id"
type="int"
column="contentID">
<generator class="foreign">
<param name="property">contentTitle</param>
</generator>
</id>

<one-to-one name="contentTitle"
class="ContentTitle"
constrained="true"/>



Code between sessionFactory.openSession() and session.close():
ContentTitle contentTitle = new ContentTitle();

contentTitle.setId(1);

CableLabSpec clSpec = new CableLabSpec();
<< when the CableLabSpec is created the contentTitle variable is set to a new ContentTitle ??>>

contentTitle.setCableLabSpec(clSpec);

session.save(contentTitle );

I do not get an exception, but the primary key of the row written to the CableLabSpec table is always 0. It does not take the value of the ContentTitle primary key

Sybase 12.x Enterprise

The generated SQL (show_sql=true):
I can't get this to work. I don't see the SQL on the console.


Debug level Hibernate log excerpt:


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.