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: Problems mapping a manytoone legacy association (Thanks ;-))
PostPosted: Mon Mar 17, 2008 8:07 am 
Newbie

Joined: Thu May 26, 2005 7:25 am
Posts: 13
Hibernate version: 3

Mapping documents: Annotations

Hi! I have what I think is a quite common situation and I'm just not able to find the appropriate mapping for it. It's a legacy (read, unnormalized) manytoone relationship between two tables that represents a single entity. This is a simplification of the situation:

Code:
CREATE TABLE cities
  (id varchar(8) primary key,
   name varchar(32), region char(4))


example: BAR87432, "Barcelona", "CAT"

Code:
CREATE TABLE territories
  (regionCode varchar(12) primary key, region char(4))

example: CATA12345678, CAT


Code:
class City {

   String id;               <-- city
   String name;          <-- city
   String regionCode;  <-- territory

}


As you can see, the join is performed over an unique but non-primary-key field (region) and the only property I want to set is the regionCode string value.

Secondary tables doesn't work and I'm just not able to map a ManyToOne because the target property is a String.

Any help would be very appreciated :-)

jv


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 17, 2008 1:36 pm 
Beginner
Beginner

Joined: Wed Mar 05, 2008 4:57 am
Posts: 22
Location: Bangalore,India
You can make us of the folowing mapping in the City class mapping provided you change the

String regionCode; --------------to--------------- Territory regionCode;

String class needs to be replaced by Territory class.

<many-to-one name="regionCode" column="regionID" element-ref="region" />

In the above mapping, element-ref will ask the hibernate framework not to use primary key of Territory class instead use what I have given i.e. region.

_________________
Naresh Waswani
+91-9986461501


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 18, 2008 7:22 am 
Newbie

Joined: Thu May 26, 2005 7:25 am
Posts: 13
Thanks a lot waswani :-) But in fact we don't have a Territory entity and we would prefer not to create it: we only need the regionCode as a string... it's would require a long explanation but in this project it just doesn't have enough semantic weight to originate a full Entity.

So we would love to have a simple String attribute. Would it be possible?

Anyway, thanks again.


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