Committe.java
public class Committe {
private Integer id;
private Users users;
private String work;
private String position;
...
}
Users.java
public class Users {
private Integer id;
private Integer userId;
private String userName;
...
}
我想查询Committe中的work,position还有Users中的id,userId,userName。hql语句不用简单的from Committe,因为数据表中有比较大的数据这样的效率很低。单张表用select ... from ...的,多张表就不会写了。
各位大能,帮帮小弟吧。
public class Committe {
private Integer id;
private Users users;
private String work;
private String position;
...
}
Users.java
public class Users {
private Integer id;
private Integer userId;
private String userName;
...
}
我想查询Committe中的work,position还有Users中的id,userId,userName。hql语句不用简单的from Committe,因为数据表中有比较大的数据这样的效率很低。单张表用select ... from ...的,多张表就不会写了。
各位大能,帮帮小弟吧。
用sql的话:select c.`work`, c.`position`, u.*
from `committe` c
left join `users` u
on c.User_Id = u.id
试试where Committe.users.User_Id = Users.id
org.springframework.orm.hibernate3.HibernateQueryException: could not resolve property: User_Id
Committe.users.userId这样不行?
select c.`work`, c.`position`, u.*
from `committe` c
left join `users` u
on c.User_Id = u.id
")...
select a.work,a.position,a.users.id,a.users.userId,a.users.userName
from Committe a
where 1=1
and ...
2013-3-6 15:27:02 org.apache.catalina.core.ApplicationDispatcher invoke
严重: Servlet.service() for servlet jsp threw exception
java.lang.NumberFormatException: For input string: "users"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)这是怎么回事呢?
from Committe a,a.users
where 1=1
and ... 要注意这样查返回的结果是一个对象数组,数组长度是查询的字段个数。
org.springframework.orm.hibernate3.HibernateQueryException: a.users is not mapped
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "USER_ID")
public Users getUsers() {
return this.users;
}public void setUsers(Users users) {
this.users = users;
}
这个吧
类似于下面这样List<User> list = new ArrayList<User>();
Iterator it=list.iterator();
while(it.hasNext())
{
Object[] obj=(Object[])it.next();
User user=new User();
user.setName((String)obj[0]);
user.setAge(Integer.parseInt(obj[1]));
list.add(user);
}