hibernate与spring整合的问题

 
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 =

其中我只用了一次向数据库查询数据怎么这一句
Hibernate: select spring0_.id as col_0_0_ from spring spring0_ where spring0_.username=? 
要执行两此
其中查询是在spring的validator中中进行的事物管理使用spring的声明式事物管理
Spring DBuser = udao.getUserByName(user.getUsername());
而getUserByName()的定义如下
 
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; 
     }
 
 }  

而现在我有试着重新把这个方法再定义下,其改后如下
 
   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; 
      }
 

这时我重新运行这个web程序 看下运行的结果,却发现这时没有hibernate所说的lazy-load(懒集合),而是直接从database里把所有的数据加进来
其运行两次的结果如下:
 
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 =

这是否就意味着没有使用到hibernate提供的性能优化的功能呢?或者这背后还有更多的考虑呢?真是迷惑啊,还请各位指点。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值