select a.name as name, b.salary as salary from Person as a ,Salary b where a.id= b.personId ;
这个name,这是相当于你自定义的名称,可以跟你的entity实体名称对应
建议:你可以设置一个bean,用来接收你的值,bean里面的属性名称:name, salary 两个,注意加上get/set方法
然后你用这个bean来接收, List
public class Base{
private SessionFactory sessionFactory;
public SessionFactory getSessionFactory()
{
return sessionFactory;
}
public void setSessionFactory(SessionFactory sessionFactory)
{
this.sessionFactory = sessionFactory;
}
public final Session getSession()
{
return this.sessionFactory.getCurrentSession();
}
@SuppressWarnings("unchecked")
public List executeQuery(String hql)
{
return (List) this.getSession().createQuery(hql).list();//执行传入的sql,并返回一个list
}
}