-->
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.  [ 2 posts ] 
Author Message
 Post subject: One-To-One mapping with foreign key null identifier issue
PostPosted: Wed Aug 19, 2009 12:02 pm 
Newbie

Joined: Tue Dec 06, 2005 10:33 am
Posts: 4
Hi guys,

having a real hard time with this so would appreciate some help. I am trying to set up a one-to-one association and save it out but cannot get it to work. I have one table with the following:

TABLE PROFILES

ProfileId (PK)
Name

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="" assembly="">
    <class name="Profile, Assembly" table="Profile" lazy="true">
      
    <id name="Id" column="ProfileId">
          <generator class="native" />
    </id>

    <one-to-one name="Setting" class="Setting" cascade="save-update" />
    <property Name="Name" column="name"/>

    </class>
</hibernate-mapping>


SETTINGS TABLE
ProfileId (FK - to profiles table)
Setting

Code:
Hi guys,

having a real hard time with this so would appreciate some help.  I am trying to set up a one-to-one association and save it out but cannot get it to work.  I have one table with the following:

[b]TABLE PROFILES[/b]

ProfileId (PK)
Name

[code]
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="" assembly="">
    <class name="Profile, Assembly" table="Profile" lazy="true">
      
    <id name="Id" column="ProfileId">
          <generator class="native" />
    </id>

    <one-to-one name="Setting" class="Setting" cascade="save-update" />
    <property Name="Name" column="name"/>

    </class>
</hibernate-mapping>
[/code]

[b]PROFILESETTINGS TABLE[/b]
ProfileId (FK - to profiles table)
Setting

[code]
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="" assembly="">
  <class name="ProfileSetting, assembly" table="ProfileSetting" lazy="true">

    <id name="Id" column="ProfileId">
      <generator class="assigned"></generator>
    </id>

    <property name="Setting" column="Setting" />
    <one-to-one name="Profile" class="Profile" constrained="true" />
  </class>
</hibernate-mapping>


whenever I do the following:

Profile prof = new Profile;
prof.Setting = new ProfileSetting();
session.Save();

I get a null identifier and I am assuming its not assigning the setting an id (works ok If i remove the settings class) has anyone got an example please on how to set this type of scenario up?

Thanks
Mocksy.


Top
 Profile  
 
 Post subject: Re: One-To-One mapping with foreign key null identifier issue
PostPosted: Thu Aug 20, 2009 2:11 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Try this id generator on ProfileSetting:

<id name="Id" column="PERSON_ID">
<generator class="foreign">
<param name="property">Profile</param>
</generator>
</id>


http://nhforge.org/doc/nh/en/index.html#mapping-declaration-onetoone

_________________
--Wolfgang


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

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.