hibernate调用存储(返回记录集)

 
tree.hbm.xml
<? xml version = "1.0" encoding = "utf-8" ?>
<! DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<!--
    Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
< hibernate-mapping >
    < class name = "ds_soft.ltxsys.auto.ltxemp.LtxProTreeEmpFound" table = "tree_table" schema = "dbo" catalog = "dsltxsalary" >
       < id name = "id" type = "string" >
            < column name = "id" length = "32" />
            < generator class = "assigned" ></ generator >
        </ id >
        < property name = "name" type = "string" >
            < column name = "name" length = "50" />
        </ property >
        < property name = "cc" type = "integer" >
            < column name = "cc" not-null = "true" />
        </ property >
        < property name = "childn" type = "integer" >
            < column name = "childn"  not-null = "true" />
        </ property >
        < property name = "pid" type = "string" >
            < column name = "pid" length = "32" />
        </ property >
       
         < property name = "sort" type = "string" >
            < column name = "sort" length = "32" />
        </ property >        
         < property name = "imageurl" type = "string" >
            < column name = "imageurl" length = "200" />
        </ property >       
       
    </ class >
 
 
      <!-- 调用存储过程就在这里配了 -->
    < sql-query name = "getTreeEmpFound" callable = "true" >
     < return alias = "emptree" class = "ds_soft.ltxsys.auto.ltxemp.LtxProTreeEmpFound" >
     < return-property name = "id" column = "id" />
     < return-property name = "name" column = "name" />
      < return-property name = "cc" column = "cc" />
     < return-property name = "childn" column = "childn" />
     < return-property name = "pid" column = "pid" />
     < return-property name = "sort" column = "sort" ></ return-property >
     < return-property name = "imageurl" column = "imageurl" ></ return-property >
     </ return >
     <!-- 这里就是存储过程名 -->
     {call ltx_pro_tree_create(?)}
     </ sql-query >   
</ hibernate-mapping >
 
执行存储过程的通用方法
    public List findByNamedQuery(String querystr, Object[] parameters) {
       Session session = this .getSession();
       Query query = null ;
       List list = null ;
        try {
           query = session.getNamedQuery(querystr);
           if ( parameters. length < 1)
              list = query.list();
           else
           {
              for ( int i=0; i < (parameters. length );i++){
                  query.setParameter(i , parameters[i]);
              }
              list = query.list();
           }
       } catch (Exception e)
       {
           System. out .println( " 执行存储过程: " + querystr + " 参数: " );
           System. out .println(parameters);
           System. out .println( " 失败 " );
           e.printStackTrace();
       } finally {
           SessionFactoryUtils.closeSessionIfNecessary(session, this .getSessionFactory());
           return list;
       }
    }
调用通用方法:
           list = this . comService .findByNamedQuery(querystr, parameters);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值