Hello everyone,
I have two ralated entities as below:
Usersent
and
Machineent
the relation is one user to many machines. So each machine must have at
least one user.
So the relation is specify as:
public class Machineent......{
@Id
@Column(name = "COMPUTNAME", nullable = false)
private String comptername;
......
@ManyToOne()
@JoinColumn(name="USERID")
private Usersent usersent;
and:
public class Usersent.........
@Id
@Column(name="USERID", nullable=false)
private String UserID;
..........
@OneToMany(mappedBy="usersent")
private List <Machineent> machineents;
Now in the Machineent I have specified methods which should be used to set
and get data from the database of the Usersent table
public Usersent getUserID() {
return usersent;
}
public void setUserID(String UserID) {
this.usersent = usersent;}
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"),
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?
Thanks
eve
_________________________________________________________________
Txt a lot? Get Messenger FREE on your mobile.
https://livemessenger.mobile.uk.msn.com/