-->
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.  [ 2 posts ] 
Author Message
 Post subject: Internationalized data with minimal number of tables
PostPosted: Sat Dec 11, 2004 10:28 am 
Newbie

Joined: Sun Oct 12, 2003 4:21 pm
Posts: 16
Location: Stockholm, Sweden
Hibernate version: 2.1.7

Name and version of the database you are using: MsSql 2000

In my application I have many referense tables and I want the description/label to be internationalized.
I have read and tested the blog entry http://blog.hibernate.org/cgi-bin/blosxom.cgi/2004/06/#i18n.
But that example has one "label" table for each reference table. I have 50 reference tables which means 100 tables to store internationalized labels for my tables.
Instead I have implemented a mapping that has only one table holding labels for all 50 reference tables. The label table has a column that holds the reference table's primary key, then a language column and the label column.
However I could not get any standard Hibernate mapping to work with this type of mapping, so I had to do everything myself. Load and persist the right label/language with an interceptor.
But modifying the label property does not trigger an onFlushDirty. I know I had this working a few months ago, but now I broken it someway. I did not have a unit test on that before, so I don't know exactly when it stopped working. Could been a Hibernate upgrade to 2.1.7.
Before I dig deeper into the problem I want to know if there is an easier solution to this mapping situation. Or should I go for the solution in the blog entry and accept 100 tables instead of 51? If xdoclet could automatically generate the supporting i18n-table for each reference table, I could accept it.
I hope you can help me with a smart solution. Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 15, 2004 11:55 am 
Newbie

Joined: Sun Oct 12, 2003 4:21 pm
Posts: 16
Location: Stockholm, Sweden
Forget my above question, it is somewhat wrong and confusing.
But my problem still remains. I'll try to explain it again with an example this time.
This is what I want to do:
    * My primary keys are unique within the database. A specific primary key can not exist in other tables.
    * All internationalized labels for all reference tables should be stored in one table.
    * Labels should be cached to reduce lookups in the single label table.
    * Modifying a label should persist it automatically.
    * Deleting a record should delete all records owned by that record in the label table.

Code:
create table Label (
    owner bigint not null,
    language char(5) not null,
    description varchar(100) not null,
    primary key(owner, langauge)
)

create table CategoryA (
    id bigint not null primary key,
    name varchar(20) not null
)

create table CategoryB (
    id bigint not null primary key,
    name varchar(20) not null
)

create table CategoryC (
    id bigint not null primary key,
    name varchar(20) not null,
)

public abstract class Category {
    private Long id;
    private String name; // Name used in configuration.
    private Map labels; // Labels keyed by language.
   
    public String getLabel(String language) {
       return (String)labels.get(lang);
    }
   
    public String getLabel() {
       return getLabel(getDefaultLanguage());
    }
   
    public void setLabel(String language, String value) {
       labels.put(language, value);
    }
   
    public void setLabel(String value) {
       setLabel(getDefaultLanguage(), value);
    }
}

public class CategoryA extends Category {
}

public class CategoryB extends Category {
}

public class CategoryC extends Category {
}

Category a = new CategoryA();
a.setName("hello");
a.setLabel("Hello", "us_en");
a.setLabel("Hej", "se_sv");
a.setLabel("Hei", "fi_fi");

Category b = new CategoryB();
b.setName("world");
b.setLabel("World", "us_en");

session.save(a);
session.save(b);

The above code sample should create one record in the CategoryA table,
one record in the CategoryB table, and four records in the Label table.

Is this possible in Hibernate 2 with a UserType or something?
Will it be possible/easier in Hibernate 3?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.