`
seawavecau
  • 浏览: 748751 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

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.    



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.      



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

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics