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?