
hql = "select distinct u from User " 跪求高手指导此hql 怎么写
hql="selectdistinctufromUser"跪求高手指导此hql怎么写用hql查询User的时候,只(ˇˍˇ)想~查出User以及User.Sta...
hql = "select distinct u from User " 跪求高手指导此hql 怎么写
用hql查询User 的时候, 只(ˇˍˇ) 想~查出User 以及User .Station.id、User .Station.name、.User Station.dept,以及User Station.dept.id、User Station.dept.name 因为不这样的话 执行效率太低了。页面刷新很慢%>_<%
public class User implements Serializable{
private String id;
private String username;
private UserInfo userInfo;
private Set<Station> stations;
private Set<Role> roles;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public UserInfo getUserInfo() {
return userInfo;
}
public void setUserInfo(UserInfo userInfo) {
this.userInfo = userInfo;
}
public Set<Station> getStations() {
return stations;
}
public void setStations(Set<Station> stations) {
this.stations = stations;
}
public Set<Role> getRoles() {
return roles;
}
public void setRoles(Set<Role> roles) {
this.roles = roles;
}
跪求高手指导hibernate此hql 怎么写 展开
用hql查询User 的时候, 只(ˇˍˇ) 想~查出User 以及User .Station.id、User .Station.name、.User Station.dept,以及User Station.dept.id、User Station.dept.name 因为不这样的话 执行效率太低了。页面刷新很慢%>_<%
public class User implements Serializable{
private String id;
private String username;
private UserInfo userInfo;
private Set<Station> stations;
private Set<Role> roles;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public UserInfo getUserInfo() {
return userInfo;
}
public void setUserInfo(UserInfo userInfo) {
this.userInfo = userInfo;
}
public Set<Station> getStations() {
return stations;
}
public void setStations(Set<Station> stations) {
this.stations = stations;
}
public Set<Role> getRoles() {
return roles;
}
public void setRoles(Set<Role> roles) {
this.roles = roles;
}
跪求高手指导hibernate此hql 怎么写 展开
2个回答
展开全部
写sql行吗
hql你牵扯到两个以上的对象 并且你仔细看user和station对应的关系是一对多的关系
你上面写的user.station.id明显是错的,station和dept对应关系不知道 姑且认为是一对一
照你的需求来的话 sql应该这样写
select s.id,s.'name',d.id,d.'name' from User u,Station s,Dept d where u.id = s.user_id and d.station_id = s.id and u.id = ?
多表的话用hql应该会非常慢。
hql你牵扯到两个以上的对象 并且你仔细看user和station对应的关系是一对多的关系
你上面写的user.station.id明显是错的,station和dept对应关系不知道 姑且认为是一对一
照你的需求来的话 sql应该这样写
select s.id,s.'name',d.id,d.'name' from User u,Station s,Dept d where u.id = s.user_id and d.station_id = s.id and u.id = ?
多表的话用hql应该会非常慢。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询