Hibernate Call SPs

First I am going to post the Named Query configuration

  1.     
  2. <?xml version="1.0" encoding="UTF-8"?>   
  1.     
  2. <!DOCTYPE hibernate-mapping PUBLIC   
  3.     "-//Hibernate/Hibernate Mapping DTD 3.0//EN"    
  4.     "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">   
  5.     
  6. <hibernate-mapping>     
  7.   <sql-query name="selectPaymentMaster_SP" callable="true">   
  8. <return alias="paymentMaster" class="com.gateway.payment.model.PaymentMaster">   
  9.   
  10. </return>   
  11. { call OC_PAYMENT_METHOD_SEL(?,  :-P     aymentTypeCode, :callingAPI) }   
  12.   </sql-query>   
  13. </hibernate-mapping>   
  14.    

<?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"> <hibernate-mapping> <sql-query name="selectPaymentMaster_SP" callable="true"> <return alias="paymentMaster" class="com.gateway.payment.model.PaymentMaster"> </return> { call OC_PAYMENT_METHOD_SEL(?, :-P aymentTypeCode, :callingAPI) } </sql-query> </hibernate-mapping>

So that maps a Stored procedure called OC_PAYMENT_METHOD_SEL and the return type to map to the PaymentMaster DTO Java class that we have that actually maps to the PaymentMaster table in our database.

Now here is our Java code to call this stored procedure.

  1.     
  2. public List<PaymentMaster> search(PaymentMasterSearch paymentMasterSearchValue) throws PaymentException {   
  3.         LOGGER.debug(" $$$---Start of search  method in the  PaymentMasterService:");   
  4.         Session sessionObj;   
  5.         List<PaymentMaster> paymentMasterlist;   
  6.         try {   
  7.             if (paymentMasterSearchValue != null) {   
  8.                 sessionObj = HibernateUtil.currentSession();   
  9.     
  10.                 String keyWord = paymentMasterSearchValue.getSearchKeyWord();   
  11.                 paymentMasterlist = sessionObj.getNamedQuery("selectPaymentMaster_SP")   
  12.                         .setParameter("paymentTypeCode", keyWord)   
  13.                         .setParameter("callingAPI""OC25")   
  14.                         .list();   
  15.                 HibernateUtil.closeSession();   
  16.     
  17.             } else {   
  18.                 LOGGER   
  19.                         .debug(" $$$--Invalid payment master Search data.");   
  20.                 throw new PaymentException(   
  21.                         "Invalid payment master Search data.");   
  22.             }   
  23.     
  24.         } catch (Exception ex) {   
  25.             LOGGER.error("Could not find a payment master Record." , ex);   
  26.             throw new PaymentException("Error in  Proccessing the search method.",ex);   
  27.         }   
  28.         return paymentMasterlist;   
  29.     }   
  30.      

public List<PaymentMaster> search(PaymentMasterSearch paymentMasterSearchValue) throws PaymentException { LOGGER.debug(" $$$---Start of search method in the PaymentMasterService:"); Session sessionObj; List<PaymentMaster> paymentMasterlist; try { if (paymentMasterSearchValue != null) { sessionObj = HibernateUtil.currentSession(); String keyWord = paymentMasterSearchValue.getSearchKeyWord(); paymentMasterlist = sessionObj.getNamedQuery("selectPaymentMaster_SP") .setParameter("paymentTypeCode", keyWord) .setParameter("callingAPI", "OC25") .list(); HibernateUtil.closeSession(); } else { LOGGER .debug(" $$$--Invalid payment master Search data."); throw new PaymentException( "Invalid payment master Search data."); } } catch (Exception ex) { LOGGER.error("Could not find a payment master Record." , ex); throw new PaymentException("Error in Proccessing the search method.",ex); } return paymentMasterlist; }

I'd post the DTO, but there isn't anything different about it from other DTOs that map to database tables.

I hope that helps.

Mark

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值