-->
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: one-to-one with Primary keys
PostPosted: Fri Oct 21, 2005 1:31 am 
Newbie

Joined: Fri Oct 21, 2005 1:01 am
Posts: 1
Hi.
I am having difficulty with a one-to-one relationship.

Here is my schema

create table User (user_id int(5) not null auto_increment,
user_name varchar(10) not null);
user_id - primary key

create table Admin(admin_id int(5) not null, admin_name varchar(10) not null);
admin_id - primary key.

<class name="User" table="User">
<id name="user_id" column="user_id">
<generator class="native"/>
</id>
<property name="userName" column="user_name" type="string" />
<one-to-one name="admin" class="Admin" cascade="save-update"/>
</class>


<class name="Admin" table="Admin">
<id name="admin_id" column="admin_id">
<generator class="foreign"/>
<param name="property">user</param>
</generator>
</id>
<property name="adminName" column="admin_name" type="string" />

<one-to-one name="user" class="User" constrained="true"/>
</class>


When I try to insert a new user (which should also insert admin)

User user = new User();
user.setUserName("dummy");

Admin admin = new Admin();
admin.setAdminName("adminuser");

user.setAdmin(admin);
admin.setUser(user);

session.save(user);

I am getting either "null id generated for class Admin" or if I change the order then I am getting cannot add or update child row.

please help


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.