hibernate与spring整合的问题

[code]Hibernate: select spring0_.id as col_0_0_ from spring spring0_ where spring0_.username=?
Hibernate: select spring0_.id as col_0_0_ from spring spring0_ where spring0_.username=?
Hibernate: select spring0_.id as id0_0_, spring0_.username as username0_0_, spring0_.password as password0_0_ from spring spring0_ where spring0_.id=?
Hibernate: select spring0_.id as col_0_0_ from spring spring0_ where spring0_.username=?
Hibernate: select spring0_.id as col_0_0_ from spring spring0_ where spring0_.username=?
Hibernate: select spring0_.id as id0_0_, spring0_.username as username0_0_, spring0_.password as password0_0_ from spring spring0_ where spring0_.id=?
Hibernate: select spring0_.id as col_0_0_ from spring spring0_ where spring0_.username=?
Hibernate: select spring0_.id as col_0_0_ from spring spring0_ where spring0_.username=?
Hibernate: select spring0_.id as id0_0_, spring0_.username as username0_0_, spring0_.password as password0_0_ from spring spring0_ where spring0_.id=?
[/code]
其中我只用了一次向数据库查询数据怎么这一句
[code]Hibernate: select spring0_.id as col_0_0_ from spring spring0_ where spring0_.username=?[/code]要执行两此
其中查询是在spring的validator中中进行的事物管理使用spring的声明式事物管理
[quote]Spring DBuser = udao.getUserByName(user.getUsername());[/quote]
而getUserByName()的定义如下
[code]public class SpringDaoImpl extends HibernateDaoSupport implements SpringDao {

public Spring getUserByName(String name) {
Session session = this.getSession();
Query q = session.createQuery("from Spring s where s.username=?");
q.setString(0, name);
Spring user = null;
if(q.iterate().hasNext())
{
user = (Spring) q.iterate().next();
}
return user;
}
}[/code]
而现在我有试着重新把这个方法再定义下,其改后如下
[code]public Spring getUserByName(String name) {
List list = this.getHibernateTemplate().findByNamedParam(
"from Spring s where s.username=:name", "name", name);
Iterator it = list.iterator();
Spring user = null;
if (it.hasNext()) {
user = (Spring) it.next();
}
return user;
}[/code]
这时我重新运行这个web程序 看下运行的结果,却发现这时没有hibernate所说的lazy-load(懒集合),而是直接从database里把所有的数据加进来
其运行两次的结果如下:
[code]Hibernate: select spring0_.id as id0_, spring0_.username as username0_, spring0_.password as password0_ from spring spring0_ where spring0_.username=?
Hibernate: select spring0_.id as id0_, spring0_.username as username0_, spring0_.password as password0_ from spring spring0_ where spring0_.username=?
[/code]
这是否就意味着没有使用到hibernate提供的性能优化的功能呢?或者这背后还有更多的考虑呢?真是迷惑啊,还请各位指点。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值