ejb@glassfish.java.net

Re: retrieving data from two related entities(table)

From: Wonseok Kim <guruwons_at_gmail.com>
Date: Thu, 26 Apr 2007 13:35:44 +0900

Hi Eve,
You might get more answers if you send email to
persistence_at_glassfish.dev.java.net list.

My comments are inline...

On 4/25/07, Eve Pokua <gorgeous65_at_msn.com> wrote:
>
> Hello everyone,
>
> I have a query as:
>
> @NamedQuery(name = "Machineent.findMachinebyuser",query = "SELECT us FROM
> Usersent us WHERE us.UserID=:UserID")
>
> I also tried the following query.
>
> @NamedQuery(name = "Machineent.findMachinebyuser",query = "SELECT m FROM
> Machineent m JOIN m.usersent us WHERE us.UserID=:UserID"),


Those two named query has the same name. Is it just your typo or mistake in
the code?

In my client I have:
>
> List<Machineent> machineent =machbean.searchbyusername ("u");
>
>
>
> for (Machineent allmachlist: machineent){
>
>
> out.println("<td>");
> out.println(allmachlist.getcompModle());out.println("</td>");
> out.println ("<td>");
> out.println(allmachlist.getcomptername());out.println("</td>");
> out.println("<td>");
> out.println(allmachlist.getUserID());out.println("</td>");
> }
>
> but it does not do exactly what I am looking for. The bottom line is, I
> would like to able to retrieve data from both or either tables of the
> entities. What is the best way to go about this?


I could not get an clear understanding what you're looking for. Could you
tell more detail?
If you are looking for outer join, you could still use it in JPQL. Or are
you looking for projection feature like below?

SELECT new XXX(e.id, e.name, e.salary, e.status, d.name)
       FROM Employee e JOIN e.department d WHERE e.address.state = ?1

Regards,
-Wonseok