-->
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: Strill have problem
PostPosted: Tue Jun 10, 2008 9:31 am 
Newbie

Joined: Tue Jun 10, 2008 5:12 am
Posts: 6
I am sorry. But I still have problem.

Let's me explain :

I have Countries table

table Countries {
int id;
int name;
}

that has e.g. two entries
Countries.id = 1
Countries.name = 'USA'

Countries.id = 2
Countries.name = 'Japan'

Also I have Addresses table :

table Addresses {
int id;
int countryId;
}


Also I have JavaBeans

class Country {
int id;
String name;
}

class Address {
int id;
Country country;
}

I develop .hbm :

<hibernate-mapping>
<class name="Country" table="Countries">
<id name="id" column="id" unsaved-value="null">
<generator class="increment"/>
</id>
<property name="name" column="name" not-null="true"/>
</class>
<class name="Address" table="Addresses">
<id name="id" column="id" unsaved-value="null">
<generator class="increment"/>
</id>
<???-to-??? name="country" class="Country" column="countryId" />
</many-to-one>
</class>
</hibernate-mapping>

Which association should I use here? many-to-one or one-to-one or something else ?

Could you please give me example?

Also I have the following data in Addresses table
Addresses.id = 1
Addresses.countryId=1

Addresses.id = 2
Addresses.countryId=2

Addresses.id = 1
Addresses.countryId=2

Thanks,
Aritomo

Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 13, 2008 3:43 pm 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Use Many-to-one.

So if you want to have the list of address associated with a country you can create a addressList in the Country class to retrieve it

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 13, 2008 6:48 pm 
Beginner
Beginner

Joined: Tue Dec 12, 2006 6:43 am
Posts: 32
Location: London
Hi,

I would like to suggest and Address to be a course grain type
The Address is aggregated into the country as a one-one relation.
It all depend on design decision.

the below is another alternative of the one-to-one association.


<hibernate-mapping>
<class name="Country" table="Countries">
<id name="id" column="id" unsaved-value="null">
<generator class="increment"/>
</id>
<property name="name" column="name" not-null="true"/>

<component name="Address" class="Address">
<property name="location"/>
</component>

</class>


</hibernate-mapping>

_________________
Alan Mehio
London
UK


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.