wood burning stoves
The moose likes Object Relational Mapping and the fly likes Hibernate I18N Repeated column with composite IDs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate I18N Repeated column with composite IDs" Watch "Hibernate I18N Repeated column with composite IDs" New topic

Hibernate I18N Repeated column with composite IDs

iago moure

Joined: Apr 23, 2009
Posts: 2

I have a problem with hibernate mappings when I try to map i18n lookup tables. I have to develop an international site, so I decided to create the lookup tables with i18n inside using composite ids. Example with the table gender, with two languages (1 = English, 2= Spanish).
1 | MALE | 1
2 | FEMALE | 1
1 | HOMBRE | 2
2 | MUJER | 2

The composite id in the previous table is: ID_GENDER + ID_LANGUAGE. The purpose of this technique is quite obvious, when the customer change the language in the web, the properties AND the lookup tables content changes as well.

So I extend the idea to all my lookup tables, netbeans hibernate wizards converts each lookup tables in two pojos, i.e. TmGender and TmGenderId (with the composite id).

I mapping all my classes in hibernate.cfg.xml and everything looks perfect until this point, but when I try to used this lookup tables within a POJO with JPA annotations:

When I try to used the result is: "Initial SessionFactory creation failed.org.hibernate.MappingException: Repeated column in mapping ..."

And well yes, there is a repetition in ID_LANGUAGE but the problem is that MUST BE a repetition because the same pojo could use many lookup tables, and all of them must have this kind of many to one relationship.

I can not change the values of "insertable" and "updatable" because I need this data to be inserted.

Any help would be welcomed, I am started to do this:

Thank you in advance!.

Doug MacKenzie

Joined: Feb 18, 2009
Posts: 13
This may be of help

I changed my mappings to one-to-many to get around this.
iago moure

Joined: Apr 23, 2009
Posts: 2
Thank you for your answer,

SO my problem is a detected bug since 3.1 version and still unresolved... Unbelievable.

Well, I tried to apply your work around suggestion, but I doesn't work to me. After converts my ManyToOne in OneToMany Hibernate says that
"Unable to find column with logical name: ID_GENDER"

Maybe I don't make the OneToMany relationship well...

Thank you anyway.
I agree. Here's the link: http://aspose.com/file-tools
subject: Hibernate I18N Repeated column with composite IDs
jQuery in Action, 3rd edition