-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: JPA question and i18n problem
PostPosted: Thu Jul 10, 2008 7:31 am 
Newbie

Joined: Thu Apr 05, 2007 5:57 am
Posts: 10
Hibernate version: 3.2.6-ga

Mapping documents:


Name and version of the database you are using:mysql 5.0

The generated SQL (show_sql=true): Hibernate:
/* named HQL query Sculpture.findBySculptureID */ select
sculpture0_.sculpture_ID as sculpture1_2_,
sculpture0_.actif as actif2_,
sculpture0_.annee as annee2_,
sculpture0_.hauteur as hauteur2_,
sculpture0_.largeur as largeur2_,
sculpture0_.nombreExemplaires as nombreEx6_2_,
sculpture0_.prix as prix2_
from
jbm.Sculpture sculpture0_
where
sculpture0_.sculpture_ID=?
Hibernate:
/* load one-to-many com.jeanbaptistemartin.domain.Sculpture.sculpturei18nCollection */ select
sculpturei0_.sculpture_id as sculpture2_1_,
sculpturei0_.locale as locale1_,
sculpturei0_.locale as locale1_0_,
sculpturei0_.sculpture_id as sculpture2_1_0_,
sculpturei0_.description as descript3_1_0_,
sculpturei0_.titre as titre1_0_
from
jbm.Sculpture_i18n sculpturei0_
where
sculpturei0_.sculpture_id=?



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)
);



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();
}


Does anyone have any sugggestion?

Julien.

PS The pk of sculpturei18n is the composition of "sculptureid" and "locale"


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 10, 2008 9:22 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

I probably would use a Map. Something like this:

Code:
@MapKey(name="locale")
@OneToMany(mappedBy="sculpture")
private Map<String, SculptureI18n>


SculptureI18n would be an @Embeddable class containing the title and description.

If it does not work with the JPA annotations I would have a look at Hibernate's @CollectionOfElements.

Also have a look at: http://i-proving.ca/space/Technologies/Hibernate/Hibernate+Annotation+Examples/Collection+of+Elements.

I haven't actually tried this yet, so this are just suggestions into the (hopefully) right direction ;-)

--Hardy


Top
 Profile  
 
 Post subject: Thanks a lot!!
PostPosted: Thu Jul 10, 2008 5:43 pm 
Newbie

Joined: Thu Apr 05, 2007 5:57 am
Posts: 10
Thanks a lot,
It works!
Julien.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.