-->
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.  [ 1 post ] 
Author Message
 Post subject: using Hibernate <any> mapping, need some help please
PostPosted: Sat Mar 31, 2007 12:14 pm 
Newbie

Joined: Sat Mar 31, 2007 12:06 pm
Posts: 2
Hello,

I hope someone in this group would be able to help me.
I would like to use hibernate's <any> mapping (as described in
http://www-128.ibm.com/developerworks/j ... hibernate/)

I have a USERS table. each user in linked to a city (many -> one). The
reason for using <any> is that cities are stored in tables depending
on the country they belong to, so I have CITIES_FR, CITIES_BE,
CITIES_UK, CITIES_SP .etc... The CITIES_XX tables are different, they
have in common the fact that they have a primary key 'id' and a name
'name'. Each city table is mapped to a separate class:-
CITIES_FR is mapped to the class CityFr
CITIES_BE is mapped to the class CityBe
CITIES_UK is mapped to the class CityUk
.etc...

CityFr, CityBe, CityUk all inherit from the abstract base class
AbstractCity (that have only the members id and name)

The USERS table contains information about the users, a column called
'city_ref' refering to the id (primary key) in one of the CITIES_XX
table and a column called country_code (that can be "fr", "be",
"uk" .etc...) used as a discriminator so that Hibernate knows what
CITIES_XX table is the appropriate one for the mapping.

The syntax of the <any> tag in hibernate mapping file is quite
understandable, one can find examples of this mapping the internet.
The probleme is that I cannot find anywhere java sample showing how to
use it :-/ ...
For example, how does one create a new user, telling hibernate that
his city is, let's say "London" (uk) in the table CITIES_UK? Am I
suppose to set city_ref and country_code only and hibernates performs
the magic?
Another example would be how does it work when I retrieve an existing
user from the database via Hibernate? will the corresponding city
object (e.g. CityFr) be retrieved automatically when I fetch the user?
how about 'city_ref' and 'country_code', would they be fetched
automatically? This mechanism is not clear at all to me. Something
else not clear is that the <any> tag does not have a 'not-null' or
even a 'fetch' attribute ...

Could anyone please help me to see clear in what seems to be yet
another greate feature of Hibernate? I spent 2 days on this trying to
understand it without any success. Sample code would be appreciated.

May thanks for helping me out!


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

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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.