我来了! 在实体里面 建立一个有参构造函数,
public District(Integer id,String name) {
this.id=id;
this.name=name;
} public Street(Integer id,String name) {
this.id = id;
this.name = name;
}查询的时候这样,。。
/**
* 获得所有的街道
*/
@SuppressWarnings("unchecked")
public List<District> queryAll() {
Session hs = null;
List<District> listD = new ArrayList<District>();
try {
hs = HibernateSessionFactory.getSession();
String hql = "SELECT new District(d.id,d.name) from District d";
Query query = hs.createQuery(hql);
List list = query.list();
for (int i=0;i<list.size(); i++) {
District district = (District)list.get(i);
listD.add(district);
}
} catch (HibernateException e) {
e.printStackTrace();
} finally{
hs.close();
}
return listD;
}给分哦
public District(Integer id,String name) {
this.id=id;
this.name=name;
} public Street(Integer id,String name) {
this.id = id;
this.name = name;
}查询的时候这样,。。
/**
* 获得所有的街道
*/
@SuppressWarnings("unchecked")
public List<District> queryAll() {
Session hs = null;
List<District> listD = new ArrayList<District>();
try {
hs = HibernateSessionFactory.getSession();
String hql = "SELECT new District(d.id,d.name) from District d";
Query query = hs.createQuery(hql);
List list = query.list();
for (int i=0;i<list.size(); i++) {
District district = (District)list.get(i);
listD.add(district);
}
} catch (HibernateException e) {
e.printStackTrace();
} finally{
hs.close();
}
return listD;
}给分哦
解决方案 »
- 关于电子口岸xml报文设计
- 我真的无路可走了吗?
- 请教以下问题
- jsf 怎么取得 web.xml 上的 context > param 的value值。好象我要表达的意思应该是 jsf 怎么取的一个 servletContextEvent 吧。
- 请问有没有java调用php写的web service的实例?
- struts中的logic的使用!!!求助!!!!!急急急!!!!
- jboss的非事务连接和tomcat的数据库连接池比较起来有什么不同??
- 用SMTP协议,不用URL类,怎样编写一个邮件系统。
- struts2拦截器获取HTTPsession失败
- 各位大牛 java实现Comparable接口排序的话除了要重写compareTo方法 还必须覆盖equals()和hashCode() 吗
- 关于io
- 小妹学编程,在线求助。。。
你可以看下我的博客