Hibernate Call SPs
First I am going to post the Named Query configuration
<?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>
<?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>
SothatmapsaStoredprocedurecalledOC_PAYMENT_METHOD_SELandthereturntypetomaptothePaymentMasterDTOJavaclassthatwehavethatactuallymapstothePaymentMastertableinourdatabase.
NowhereisourJavacodetocallthisstoredprocedure.
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; }
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'dposttheDTO,butthereisn'tanythingdifferentaboutitfromotherDTOsthatmaptodatabasetables.
Ihopethathelps.
Mark