persistence@glassfish.java.net

Re: question on entity relationships

From: Michael Bouschen <mbo.tech_at_spree.de>
Date: Mon, 03 Dec 2007 08:44:48 +0100

Hi Eve,

your query only returns data for LamManufacturerent instances having
related Lampent instances (meaning having at least one Lampent instance
in the list relationship).

Another question: do you get different results, if you navigate the
relation from the other side:
SELECT l.pnumb, l.catergory, l.lwoltage, lm.manuname FROM Lampent l JOIN
l.lamManufacturerent lm

Regards Michael

>
>
>
>
> Hello James/Everyone,
>
> I have finally tried your suggestion but I'm having problems retrieving data.
>
> Below are my to related entities with their relationships:
>
>
>
> *_at_Entity
> @Table(name="LAMPS")
>
>
>
> @Named Queries({
> @Named Query(name ="getAlldetails", query=" SELECT l.pnumb, l.catergory, l.lwoltage, lm.manuname FROM LamManufacturerent lm, in(lm.lampent) l")}
>
> public class Lampent implements Serializable{
>
> ..............
> ...........
>
>
> @ManyToOne
> private LamManufacturerent lamManufacturerent;
> ...................
>
> }
>
> @Entity
> @Table(name="LAMPMANU")
>
> public class LamManufacturerent implements Serializable{
> .............
> ...............
>
> @OneToMany(mappedBy = "lamManufacturerent")
> private List<Lampent> lampent;
> *
> .............
>
> }
>
>
> Here is the JPQL:
>
> *_at_Named Query(name ="getAlldetails", query=" SELECT l.pnumb, l.catergory, l.lwoltage, lm.manuname FROM LamManufacturerent lm, in(lm.lampent) l")
>
> *Did I get it wrong because it is not working and not retrieving any data. It however works, if I do some thing like this:
>
> "Select l FROM Lampent l"
>
> It brings all data plus all the data from the related entity LamManufacturerent. But i only want manuname from LamManufacturerent.
>
> Im probably making just a little mistake. Please, help.
>
> Thanks
> eve
>
> ________________________________
> > From: gorgeous65_at_msn.com
> > To: persistence_at_glassfish.dev.java.net
> > Date: Wed, 14 Nov 2007 15:07:03 +0000
> > Subject: RE: question on entity relationships
> >
> > Thanks James
> >
> > I will try it and let you know.
> >
> > eve
> >
> >> Date: Wed, 14 Nov 2007 06:20:25 -0800
> >> From: jamesssss_at_yahoo.com
> >> To: persistence_at_glassfish.dev.java.net
> >> Subject: Re: question on entity relationships
> >>
> >>
> >> The JPQL would be,
> >>
> >> "Select i.id, i.name, i.description, i.colour, i.size, o.oid, o.date,
> >> o.quantity from Order o, in(o.items) i"
> >>
> >> You could also just select the Order and fetch join the items, if you wanted
> >> the objects back. Or just select the Orders can access the items from them
> >> in Java.
> >>
> >> "Select o from Order o join fetch o.items"
> >>
> >> "Select o from Order o"
> >>
> >>
> >> Eve Pokua wrote:
> >>>
> >>>
> >>> Hello everyone,
> >>>
> >>> I would like to know how to retrieve certain data from the DB with respect
> >>> to entity relationship. Consider the following SQL statement.
> >>>
> >>> "Select i.id, i.name, i.description, i.colour, i.size, o.oid, o.date,
> >>> o.quantity from Item i, Order o"
> >>>
> >>> Or a very complex SQL statement using JOIN in tables.
> >>>
> >>> The Order entity is a 1 to many relation to Item - an order can have many
> >>> items. But when retrieving the details from order, I want to see certain
> >>> data from the Order table as stated above, but not all the data from
> >>> Order. How do I achieve this in EJB3 query?
> >>>
> >>> Thanks
> >>>
> >>> eve
> >>>
> >>
> >>
> >> -----
> >> ---
> >> http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland
> >> http://www.oracle.com/technology/products/ias/toplink/ Oracle TopLink ,
> >> http://www.eclipse.org/eclipselink/
> >> EclipseLink , https://glassfish.dev.java.net/javaee5/persistence/ TopLink
> >> Essentials
> >> Wiki: http://en.wikibooks.org/wiki/Java_Persistence Java Persistence ,
> >> http://wiki.eclipse.org/EclipseLink EclipseLink
> >> Forums: http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink ,
> >> http://www.nabble.com/EclipseLink-f26430.html EclipseLink ,
> >> http://www.nabble.com/java.net---glassfish-persistence-f13455.html Glassfish
> >> Persistence
> >> --
> >> View this message in context: http://www.nabble.com/question-on-entity-relationships-tf4804935.html#a13747259
> >> Sent from the java.net - glassfish persistence mailing list archive at Nabble.com.
> >
> > ________________________________
> > Get free emoticon packs and customisation from Windows Live. Pimp My Live!<http://www.pimpmylive.co.uk <http://www.pimpmylive.co.uk/>>
>
>
> ------------------------------------------------------------------------
> Are you the Quizmaster? Play BrainBattle with a friend now!
> <http://specials.uk.msn.com/brainbattle>


-- 
Tech_at_Spree Engineering GmbH  Tel.: +49/(0)30/235 520-33
Buelowstr. 66                Fax.: +49/(0)30/217 520-12
10783 Berlin                 mailto:mbo.tech_at_spree.de 
 
Geschaeftsfuehrung: Anna-Kristin Proefrock
Sitz Berlin, Amtsgericht Charlottenburg, HRB 564 52