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>
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.
- 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'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