-->
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.  [ 3 posts ] 
Author Message
 Post subject: Addres and Country relationship mapping question
PostPosted: Wed Oct 24, 2007 11:54 am 
Newbie

Joined: Thu Jun 14, 2007 6:14 pm
Posts: 15
I am having trouble understand what I thought would be a simple mapping, but there is something I am missing. I have tried to simplify this example as much as possible to get to the core of it.

I have a Country class,

Code:
public class Country {
private long id;
private String code;
private String name;

// getters and setters
...
}


and an Address class

Code:
{
public class Address {
private long id;
private String state;
private Country country;

// getters and setters
...
}


The database schema for these classes is like so:

Code:
Table: Addresses
id
state
countryId


Code:
Table: Countries
id
code
name


So what mapping strategy should be used to make this relationship in the sense that when I load an Address from the database, the country object is populated with a join from the countries table, but also, and this is the part that confuses me most, when I save an Address, I don't want the countries table to try to be updated, but rather just the countryId in the Addresses table (that matches the ID in the country object)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 24, 2007 1:17 pm 
Newbie

Joined: Thu Jun 14, 2007 6:14 pm
Posts: 15
I didn't get a chance to try it yet, but was this what I was looking for?

Code:
<many-to-one name="country" class="Country" column="countryId" update="false" insert="false" />


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 24, 2007 5:31 pm 
Newbie

Joined: Thu Jun 14, 2007 6:14 pm
Posts: 15
Edit - My apologies, the above statement did in fact work when i removed the insert and update lines. I am thinking i am the only one who even read this thread ha


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