• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JPA question and i18n problem

 
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I have the following two tables:

{code}

CREATE TABLE Sculpture
(
sculpture_ID integer NOT NULL PRIMARY KEY,
hauteur integer NOT NULL,
largeur integer NOT NULL,
annee year NOT NULL,
prix double,
nombreExemplaires integer NOT NULL,
actif bool DEFAULT false NOT NULL
);

CREATE TABLE Sculpture_i18n
(
sculpture_id integer NOT NULL ,
locale char(2) NOT NULL ,
titre varchar (50) NOT NULL,
description varchar(255),
FOREIGN KEY(sculpture_id) REFERENCES Sculpture (sculpture_ID)
);

{code}

I have generated the associated entity classes using netbeans.

in the Sculpture_i18n table, I have as many lines per sculpture as there are locales in the app. Say I have two locales: French and English. I'll have the following rows in the Sculpture_i18n:

1 "en" "woman" "a woman's bust"
1 "fr" "femme" "buste de femme"
2 "en" "dog" "a black dog"
2 "fr" "chien" "un chien noir"
etc...

I want to be able to retrieve a sculpture together with its localized information using jpa.

As of now my DAO looks like that and does not handle i18n:

{code} public Sculpture findBySculptureID(Integer sculptureId) {
return (Sculpture) entityManager.createNamedQuery("Sculpture.findBySculptureID").setParameter("sculptureID", sculptureId).getSingleResult();
}
{code}

Does anyone have any sugggestion?

Julien.

PS The pk of sculpturei18n is the composition of "sculptureid" and "locale"
[ July 10, 2008: Message edited by: Julien Martin ]
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Julien, do you found a solution inbetween, I am facing the same problem! Mine is even a bit more complex: Imagine I have an entity (Exposition) which holds many Skulptures and a Skulpture could be part of several expositions, thus an M:N relationship, and the Exposition entity also holds i18n texts for itself (e.g. genre description). I have no idea how to handle this,
any help is apreciated ;-)
Thanks, Charles.
 
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The easiest solution is to define a OneToMany from Sculpture to SculptureDescription. SculptureDescription will have a composite primary key of (sculpture_id, locale).
Your app can then get which descriptor matches its local.

If you know the local ahead of time, you could make a more complex solution, depending on your JPA provider. In EclipseLink you could define a DescriptorCustomizer that would define a OneToOneMapping in code based on a selectionCriteria Expression including the current local. You could potentially also define a multiple table descriptor as such in code, but this does get complicated, and the simpler solution is probably best.
 
reply
    Bookmark Topic Watch Topic
  • New Topic