Yes Wonseok,
:
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
I am trying to do something like what you suggested above and more, like
below:
SELECT new XXX(e.id, e.name, e.salary, e.status, d.name, d.description)
FROM Employee e JOIN e.department d WHERE e.address.state = ?1
So from the join entity I would like to retrieve not just the id field but
also other fields relating to a particular id.
For example:
This is what I get when I use the following query:
@NamedQuery(name = "Machineent.findMachinebyuser",query = "SELECT m FROM
Machineent m JOIN m.usersent us WHERE us.UserID=:UserID")
null SAT Machinedetail2.Usersent_at_19455f1
So it retrieves data from the Machineent but not the usersent. Basically,
because I am calling the method from just the Machineent entity but I need
to refer to both the Machineent and usersent entities i.e both the tables
from the entities, as u suggested. My client is like below:
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>");
}
So you can understand why this:
out.println("<td>");
out.println(allmachlist.getUserID());out.println("</td>");
is only giving this:
Machinedetail2.Usersent_at_19455f1
as the getUserID():
public class Machineent implements Serializable {
..........
............
..........
public Usersent getUserID() {
return usersent;
}
I hope this helps.
Thanks
eve
>From: "Wonseok Kim" <guruwons_at_gmail.com>
>Reply-To: ejb_at_glassfish.dev.java.net
>To: ejb_at_glassfish.dev.java.net
>Subject: Re: retrieving data from two related entities(table)
>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
_________________________________________________________________
Get Hotmail, News, Sport and Entertainment from MSN on your mobile.
http://www.msn.txt4content.com/