-->
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.  [ 4 posts ] 
Author Message
 Post subject: One-to-one shared primary key mapping
PostPosted: Sat Feb 02, 2008 5:57 pm 
Newbie

Joined: Sat Dec 01, 2007 10:37 am
Posts: 12
I am having a problem mapping a one-to-one association which seems to go against all of the documentation. Just wondering if this is a bug before I tear any more hair out.

Here is the exception I am getting:

Code:
Could not find a getter for property 'PublisherId' in class 'Sp.Entity.NHibernate.PublisherLimits'


Nowhere in the docs for 1-to-1 associations with a shared PK does it say that the foreign identifier must be explicitly mapped and have the associated property in the child class. If I do map it, I get all sorts of problems when saving/updating. My child class does contain a reference to the parent 'Publisher' entity

Here are the mappings:

Code:
    <class name="Publisher" table="publisher">
        <id name="PublisherId" type="string" unsaved-value="null">
            <column name="publisher_id" />
            <generator class="assigned" />
        </id>
        <one-to-one name="PublisherLimits" class="PublisherLimits" cascade="all-delete-orphan" lazy="false" />
        ...
    </class>


Code:
    <class name="PublisherLimits" table="publisher_limits">
        <id name="PublisherId" column="publisher_id">
            <generator class="foreign">
                <param name="property">Publisher</param>
            </generator>
        </id> 
        <one-to-one name="Publisher" class="Publisher" constrained="true"/>
        ...
  </class>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 04, 2008 8:55 am 
Senior
Senior

Joined: Thu Feb 09, 2006 1:30 pm
Posts: 172
Have a look at this post and see if it helps. Use a different generator.

http://forum.hibernate.org/viewtopic.php?p=2371680


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 04, 2008 12:20 pm 
Newbie

Joined: Sat Dec 01, 2007 10:37 am
Posts: 12
Nope, that's not it. I have the generator set correctly on the child class to foreign. Thanks anyway.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 04, 2008 12:56 pm 
Senior
Senior

Joined: Thu Feb 09, 2006 1:30 pm
Posts: 172
Sorry about that, I should have read more closely.

In that case you don't have a PublisherId on your PublisherLimits class. Keep in mind that a generator is just how NHibernate assigns it its value. If it is "assigned" then NHibernate doesn't assign anything. If it is identity then it relies on the database to set it. If it is foreign it relies on the ID of the provided property.

I know this may seem a little dirty to have to create a property (you could also use a field) for a primary key value that you really never want updated (since you would update the one-to-one instead), but that's currently what is required.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.