-->
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.  [ 6 posts ] 
Author Message
 Post subject: simple mapping questions - please help
PostPosted: Mon Nov 07, 2005 2:01 pm 
Newbie

Joined: Wed Sep 28, 2005 12:24 am
Posts: 15
Hey everyone,

I think I may be making this one relationship harder on myself than I need to but the problem is it just doesnt seem right...

I have an object, Borrower that has a member called governmentMonitoring.

class Borrower{
..

private GovernmentMonitoring governmentMonitoring;

..
}

This is one to one right? The problem is that i ran the eclipse hibernate tools and they created a set of governmentMonitorings based on my table structure with a one-to-many from borrower to government monitoring and it put a unique on the foreign key (borrowerid):

<set name="governmentMonitoring" inverse="true">
<key>
<column name="borrowerId" not-null="true" unique="true" />
</key>
<one-to-many class="com.ncen.fastqual.model.loanapplication.GovernmentMonitoring" />
</set>


My question basically becomes, will hibernate intelligently see that governmentMonitoring is not a list/set and still put the correct single governmentMonitoring row from the database into the member variable in borrower?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 07, 2005 5:07 pm 
Beginner
Beginner

Joined: Sat Oct 22, 2005 11:16 pm
Posts: 40
That's not right. Create your own one-to-one mapping:

Code:
<one-to-one
        name="propertyName"                                          (1)
        class="ClassName"                                            (2)
        cascade="cascade_style"                                      (3)
        constrained="true|false"                                     (4)
        fetch="join|select"                                          (5)
        property-ref="propertyNameFromAssociatedClass"               (6)
        access="field|property|ClassName"                            (7)
        formula="any SQL expression"                                 (8)
        lazy="true|proxy|false"                                      (9)
        entity-name="EntityName"                                     (10)
        node="element-name|@attribute-name|element/@attribute|."
        embed-xml="true|false"
        foreign-key="foreign_key_name"
/>


I have no idea why the Eclipse Hibernate tool thinks your class should be using a Set.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 07, 2005 5:16 pm 
Beginner
Beginner

Joined: Wed Apr 06, 2005 9:29 pm
Posts: 24
Is there a single instance of GovernmentMonitoring for each instacne of Borrower?
One-to-one will mean that they both have the same primary key. Is that what you want?
Or, could there be more than one Borrower that has the same GovernmentMonitoring object?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 08, 2005 2:33 am 
Beginner
Beginner

Joined: Tue Oct 18, 2005 3:57 pm
Posts: 48
Location: Los Angeles, CA
From Hibernate Reference, 6.1.11:

Quote:
Alternatively, a foreign key with a unique constraint, from Employee to Person, may be expressed as:

Code:
<many-to-one name="person" class="Person" column="PERSON_ID" unique="true"/>

And this association may be made bidirectional by adding the following to the Person mapping:

Code:
<one-to-one name"employee" class="Employee" property-ref="person"/>

Your database schema may have lead the tool to believe Borrower <--> GovernmentMonitoring is a bidirectional relationship. If it is, then the tools is actually correct.

jd


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 4:37 am 
Newbie

Joined: Wed Sep 28, 2005 12:24 am
Posts: 15
i'm having a hard time getting my head around this whole bidirectional relationship thing. I dont think thats the case here.

The borrower has a single member which is called governmentMonitoring. THe governmentMonitoring cannot exist on its own. It has a borrowerId FK in it which refers to the PK on the borrower table. I think it should be a unidirectional one-to-one from borrower to governmentMonitoring. Borrower and governmentMonitoring each have their own table and own primary keys.

How do you represent this in mapping?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 8:40 am 
Senior
Senior

Joined: Mon Apr 04, 2005 8:04 am
Posts: 128
Location: Manchester, NH USA
Well, you really have 2 questions here.

1> "Why do the reverse engineering tools think that this relationship is a set?" - in my experience with the tools, this is heavily dependent on the table structure and the foreign/primary key relationships of the tables. What is the exact set of primary and foreign keys you have, and what other constraints exist on the tables?

2> "How do I properly map this relationship (independent of the results of the tools" - remember that a one-to-one mapping implies that the objects are the same - they have the same primary key values. If this is not what you want, then look at some of the other relationships -- in fact, the fact that (as you stated) the primary keys of the objects are currently not the same may be why the reverse engineering tools aren't detecting this as a one-to-one relationship.

Hope that helps?


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