HIBERNATE调用数据库自定义函数

 本文使用的是Oracle9i数据库,hibernate3.0,spring2.0,jdk6。

首先在数据库中定义函数。

1.以下是数据库中定义的函数:

        create or replace function Get_Djbh return varchar2 is
              Result varchar2(10);
              nNum Number(10);
        begin
              Select SDJLCK_SEQ.Nextval Into nNum From dual;
              Result := to_char(nNum);
          return(Result);
        end Get_Djbh;

2.以下为在dao中调用函数:

    public class BackWareHouseDAO extends HibernateDaoSupport implements IBackWareHouseDAO {

        public String getFunc() {
              String result = null;
              String sql = "select Get_Djbh from dual";
              Session session = getHibernateTemplate().getSessionFactory().openSession();
              SQLQuery query = session.createSQLQuery(sql);
              result = (String) query.uniqueResult();
              session.close();
              return result;
         }

    }

你可能感兴趣的:(DAO,sql,Hibernate)