-->
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: Type conversion for a foreign key
PostPosted: Wed Feb 23, 2005 10:27 am 
Beginner
Beginner

Joined: Wed Jan 26, 2005 5:34 am
Posts: 41
Location: France, Paris
Hibernate version: 3.0beta4

Hi,

i'd like use hibernate on an exsiting schema (that i can't modify). I have several tables (be A and B) and a special table containing some labels.
The primary key of A is a long.
The primary key of B is a string.

So the description of my labels table is:
foreign_key: string
type: string ('A' or 'B' or other for other tables)
locale: string (iso code... great idea to support natively this type in hibernate)
label: my label in the specified locale for the specified (type) object.

So, each of my objects A and B have a map of labels (key of map is the locale). I don't find how map this schema. Any idea ?

How specify:
- the type in the mapping file ? (or by another way ?)
- convert the key ?

Code:
  <class name="A" table="table_a">
    <id name="id" column="id" type="long" unsaved-value="null">
      <generator class="increment"/>
    </id>
<!-- snip properties -->
    <map name="labels" table="x_label" lazy="false">
      <key not-null="true">
        <column name="lbl_id"/>
        <!--<column name="lbl_type" formula="'A'"/>-->
      </key>
      <map-key column="loc_id" type="locale"/>
      <element column="lbl_value" type="string"/>
    </map>
</class>

_________________
Vincent


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 23, 2005 10:35 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Code:
<class name="A" table="table_a">
    <id name="id" column="id" type="long" unsaved-value="null">
      <generator class="increment"/>
    </id>
<!-- snip properties -->
    <map name="labels" table="x_label" lazy="false"
           where="lbl_type='A'">
      <key column="lbl_id"/>
      <map-key column="loc_id" type="locale"/>
      <element column="lbl_value" type="string"/>
    </map>
</class>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 23, 2005 10:51 am 
Beginner
Beginner

Joined: Wed Jan 26, 2005 5:34 am
Posts: 41
Location: France, Paris
Thans a lot. That works fine to read data... but (of course, we have not specified what write in the lbl_type column) not to write data :-/

I just found UserCollectionType interface, is that the solution ?

_________________
Vincent


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.