I am using Hibernate 3.5.a-Final as an ORM-Layer in a web application. I have several Beans with the same code sniplet, which makes me think that this design is not the best. But I can’t figure out how to implement the best in sleep mode.
Requirements
- Several classes must contain localized descriptions in several locales.
- They must be saved in db
- They should be searchable by substring for all locales (if the binding string is a substring of any description)
- Localized descriptions should be available for request without loading the master object (by identifier-master-type, type and language)
Current solution (does not solve the last requirement)
Each class contains a HashMap annotated as
@ElementCollection(fetch=FetchType.EAGER) @CollectionTable(name = "localized[X]Descriptions", joinColumns = @JoinColumn(name = "id")) @MapKeyJoinColumn(name = "locale") public Map<Locale, String> getLocalizedDescriptions() { return localizedDescriptions; }
[X] - class name
For each class, this is an extra table (generated by sleeping)
create table localized[X]Descriptions ( id integer not null, localizedDescriptions varchar(255), localizedDescriptions_KEY varchar(255), primary key (id, localizedDescriptions_KEY) )
For some reason @MapKeyJoinColumn
ignored ...
I would prefer a table like this:
create table localizedDescriptions ( class varchar(255) not null, id integer not null, locale varchar(50) not null, description varchar(255) not null, primary key (class, id, locale) )
It would be a big plus if the implementation were requested using the api criterion (which, as far as I know, is not compatible with @ElementCollection
). But I can’t figure out how to implement this. Any pointers would be very welcome