Ok, now I got it. You need to filter the list of configured locales based on
your query while retrieving the Sculpture instance(s).
As far as I know this is not possible using as target class the master of
your one-many relation, that is Sculpture (this is true both in JPA and in
JDO).
In order to achieve what you want to I guess you can succeed using
Sculpture_i18n as target class for your query. Obviously you should also
have the inverse-relation going from the former class to Sculpture just to
be sure you can properly impose your filters on Sculpture instances.

This is what I can figure out right now, but I do not know if there can be a
better approach to this. I'm relatively new to JPA, but having been a (Kodo)
JDO user for a really long time I'm quite sure this approach can be correct.

Francesco

On Thu, Jul 10, 2008 at 11:10 AM, Julien Martin <[EMAIL PROTECTED]> wrote:

> Thanks for your reply,
> Note that the problem I have is that I need to pass the locale as an
> argument to the getSculpturei18nCollection but it just does not look very
> clean to me.
> The fetch problem, I can easily sort.
> Have you got any other idea as to how to retrieve only the one line per
> sculpture and locale from Sclultpurei18n?
> Julien.
>
> @OneToMany(cascade = CascadeType.ALL, mappedBy = "sculpture")
> private Collection<Sculpturei18n> sculpturei18nCollection;
>
> 2008/7/10 Francesco Russo <[EMAIL PROTECTED]>:
>
> > Hi Julien,
> > it seems to me it's just a matter of proper fetch-configuration. I guess
> > that by default JPA does not eagerly fetch related persistent instances
> > unless you impose that.
> > You should take a closer look at the Users' Guide, maybe.
> >
> > For example here
> >
> >
> http://openjpa.apache.org/builds/1.1.0/apache-openjpa-1.1.0/docs/manual/manual.html#jpa_overview_meta_onetomanyyou
> > are suggested to use the FetchType annotation for marking those
> > references that map one-to-many relations. This should be the case for
> the
> > relation you have between Sculpture and Sculpture_i18n.
> >
> > Hope this helps,
> > Francesco
> >
> > On Thu, Jul 10, 2008 at 10:45 AM, Julien Martin <[EMAIL PROTECTED]>
> wrote:
> >
> > > 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.
> > >
> >
>

Reply via email to