-->
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: Mapping diffferent parent classes one-to-many set children
PostPosted: Wed May 16, 2007 2:04 pm 
Newbie

Joined: Wed May 16, 2007 1:35 pm
Posts: 4
Hibernate version: 3.2
Name and version of the database you are using: Oracle 10g

As part of the internationalization, I need to replace all the String properties in my classes with multi-language values.

The plan is to replace what used to be a String field in my objects with a reference to the string table.

So if I had an object called Item, that had a "Description" column that contained a string value in English, I want to replace that with a stringID that is basically a pointer to my internationalized strings table, that will hold multiple language entries per string.

Let's say I run a hardware store and my Items table looked something like this:
Code:
______________________________________________________
| ID     | DESCRIPTION | VALUE | STOCK                |
|--------|-------------|-------|----------------------|
| 10001  | Hammer      | 20    | 25                   |
|--------|-------------|-------|----------------------|
| 10002  | Bucket      | 10    | 75                   |
|--------|-------------|-------|----------------------|
| 10003  | Nail Gun    | 100   | 15                   |
|--------|-------------|-------|----------------------|
...


I want to replace it with something like this

Code:
______________________________________________________
| ID     | DESCRIPTION | VALUE | STOCK                |
|--------|-------------|-------|----------------------|
| 10001  | Hammer.desc | 20    | 25                   |
|--------|-------------|-------|----------------------|
| 10002  | Bucket.desc | 10    | 75                   |
|--------|-------------|-------|----------------------|
| 10003  | NailGun.desc| 100   | 15                   |
|--------|-------------|-------|----------------------|
...


With a one-to-many mapping to my translated strings table, which would look like this

Code:
______________________________________________________
| ID         | TYPE_ID  | VALUE      | LANGUAGE_CODE  |
|------------|----------|------------|----------------|
| 50001      | Item     | Hammer     | en             |
|------------|----------|------------|----------------|
| 50002      | Item     | martello   | it             |
|------------|----------|------------|----------------|
| 50004      | Item     | marteau    | fr             |
|------------|----------|------------|----------------|
...


So far so good, this can be accomplished with a simple Set mapping or something of the sort.


THE PROBLEM is that I need the tanslated strings table to be referenced from multiple parent tables.
For example, let's say I also had a Category table, with a "Name" column that needs to be translated.
I would now want my string table to look like this:

Code:
______________________________________________________
| ID         | TYPE_ID  | VALUE      | LANGUAGE_CODE  |
|------------|----------|------------|----------------|
| 50001      | Item     | Hammer     | en             |
|------------|----------|------------|----------------|
| 50002      | Item     | martello   | it             |
|------------|----------|------------|----------------|
| 50004      | Item     | marteau    | fr             |
|------------|----------|------------|----------------|
| ...                                                 |
|------------|----------|------------|----------------|
| 50108      | Category | Materials  | en             |
|------------|----------|------------|----------------|
| 50109      | Category | Matériaux  | fr             |
|------------|----------|------------|----------------|
...


And so on and so on for every type I have that has translatable data.
This is basically a one-to-many mapping from multiple parent tables to the same LocalizedString table, where the parent table changes based on the TYPE_ID column.

I want multiple tables to have one-to-many Set mappings to the same table. How can I configure this relationship with Hibernate?


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 17, 2007 5:33 am 
Senior
Senior

Joined: Thu May 17, 2007 2:31 am
Posts: 194
Location: Sri Lanka
Hi

I don't know exactly what you want.
But try this.
Keep a constant variable for "TYPE_ID" per different class file.

Say In Item class set TYPE_ID="Item"
in category class set TYPE_ID="Category"


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 17, 2007 7:58 pm 
Newbie

Joined: Wed May 16, 2007 1:35 pm
Posts: 4
Thanks, I've managed to figure this one out. It was pretty simple, actually.
I added the following mapping in my Item class:

/**
* @hibernate.set lazy="false" cascade="all-delete-orphan" where="entity_type='Item.description'"
* @hibernate.one-to-many class="com.blah.blah.MultiLangString"
* @hibernate.key column="entity_id"
*/
public Set<LocalizedString> getDescription() {
return description;
}

and the same thing in my Category class, the only difference being the where clause where="entity_type='Category.description'"

Hibernate automatically added a "entity_id" column to the stringtable (which MultiLangString is mapped to).


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.