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
|