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?