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: