Hi there,
I'm using the Hibernate tools to generate the database schema from my annotated classes, and I would like to have something as the following:
Code:
@Entity
public class Family
{
@Embedded
@AttributeOverride(name = "defaultLocale", column = @Column(name = "title_defaultLocale", length = 25))
private InternationalizedString title;
@Embedded
@AttributeOverride(name = "defaultLocale", column = @Column(name = "description_defaultLocale", length = 25))
private InternationalizedString description;
...
}
@Embeddable
public class InternationalizedString
{
@CollectionOfElements
@MapKey(columns = {@Column(name = "locale", length = 25)})
@Column(name = "string", length = 2500)
private Map<Locale, String> strings;
@Column(length = 25)
private Locale defaultLocale;
...
}
I've been able to override the defaultLocale attribute with @AttributeOverride as shown so I get different column names for title and description default locales, but for storing the strings Hibernate only generates a table named family_strings. Instead I would need the following table structure:
Code:
CREATE TABLE family
(
title_defaultlocale varchar(25),
description_defaultlocale varchar(25)
)
CREATE TABLE family_title_strings
(
family_id varchar(50) NOT NULL,
string varchar(2500),
locale varchar(25) NOT NULL,
CONSTRAINT family_title_strings_pkey PRIMARY KEY (family_id, locale),
CONSTRAINT family_title_fk FOREIGN KEY (family_id) REFERENCES family (id)
)
CREATE TABLE family_description_strings
(
family_id varchar(50) NOT NULL,
string varchar(2500),
locale varchar(25) NOT NULL,
CONSTRAINT family_description_strings_pkey PRIMARY KEY (family_id, locale),
CONSTRAINT family_description_fk FOREIGN KEY (family_id) REFERENCES family (id)
)
Is this possible?
Thanks in advance, best regards
Jose