The thing is, if you have 2 user records in your database with the same username then you have 2 users with the same username.
I think this is neat... you can select a subset of properties from the objects in you query and populate a bean (not an entity) using hql.
e.g. if you selected say username and age you could do the following:
Code:
package test;
public class BasicUserInfo {
private String username;
private int age;
public UserBasicInfo(String username, int age) {
this.username = username;
this.age = age;
{
public String getUsername() {
return username;
}
public int getAge() {
return age;
}
}
HQL:
select new test.BasicUserInfo(name, age) from User