I have a simply query in existing system
select server.sid , group.gid from server , group
where server.sid = 10 and group.gid in (20.30)
But I can't get corresponding criteria api for this query. I wrote the following code to load data but it does not work. What code should be added to handle gid
Code:
//Code to load data
Criteria criteria = getSession().createCriteria(Server.class);
criteria.add(Expression.eq("sid", 10));
//I thought following will work but it does not
//Collection c = new Vector();
//c.add(20);
//c.add(30);
//criteria.add(Expression.in("serverGroupList", c));
I have write following code to represent system
Code:
public class Server implements Serializable {
@Id @GeneratedValue
@Column(name="SID")
private int serverID;
@OneToMany
@JoinColumn(name="SID")
private List<ServerGroup> serverGroupList;
}
public class ServerGroup implements Serializable {
@Id @GeneratedValue
@Column(name="GID")
private int groupid;
@Column(name="SID")
private Integer serverId;
}