Integrating Hibernate and jPOS Framework

Today i want to share about Integrating Hibernate and jPOS Framework.

The implementation will based on my old post about Implementation jPOS Transaction Manager you can read the jPOS project on these post.
The jPOS System is look like:
Integrating Hibernate and jPOS Framework

i will add new participant for FinancialTransaction group called FinancialTransactionLogging, the participant is responsible for inserting the FinancialTransactionQueryRemoteHost response into database using Hibernate framework.
First, For integrating Hibernate and jPOS, i create new qbean called HibernateManager that extends org.jpos.q2.QBeanSupport the initService methods will buildSessionFactory for init the hibernate SessionFactory object.

HibernateManager class will look like:
package com.didikhari.utility;


import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.jpos.q2.QBeanSupport;
import org.jpos.util.NameRegistrar;

public class HibernateManager extends QBeanSupport {

private SessionFactory sessionFactory;

protected void initService() throws Exception {
try {
String hibernatePropsFilePath = cfg.get(“hibernate_cfg_path”);
File hibernatePropsFile = new File(hibernatePropsFilePath);

Configuration configuration = new Configuration();
sessionFactory = configuration.buildSessionFactory();
NameRegistrar.register(“hibernate-manager”, this);
} catch (Exception e) {

public SessionFactory getSessionFactory() {
return sessionFactory;

public void shutdown() {
if (getSessionFactory() != null) {
and you need to create 60_hibernate_manager.xml file inside your deploy directory. and the xml file is:


The hibernate configuration file, and inserting methods using Template Methods Pattern can be found here: Implementation Template Methods Design Pattern

The last thing i need to do is to create the FinancialTransactionLogging class implementation like this:
package com.didikhari.transaction.participant;


import org.apache.commons.beanutils.PropertyUtils;
import org.hibernate.Session;
import org.jpos.iso.ISOMsg;
import org.jpos.iso.ISOUtil;
import org.jpos.transaction.AbortParticipant;
import org.jpos.transaction.Context;

import com.didikhari.constant.Constant;
import com.didikhari.model.ResponseISO;
import com.didikhari.utility.HibernateUtil;
import com.didikhari.utility.TransactionCallAble;

* This class is responsible for log the message to the database
* @author Didik Hari
public class FinancialTransactionLogging implements AbortParticipant {

public void abort(long id, Serializable context) { }

public void commit(long id, Serializable context) { }

public int prepare(long id, Serializable context) {
try {
ISOMsg respMsg = (ISOMsg) ((Context)context).get(Constant.RESPONSE_HOST);
ResponseISO responseISO = new ResponseISO();
for (int i=2; i < 128; i++) { String prop = "bit"+ ISOUtil.zeropad(String.valueOf(i), 3); PropertyUtils.setProperty(responseISO, prop, respMsg.getString(i)); } save(responseISO); } catch (Exception e) { e.printStackTrace(); return ABORTED; } return PREPARED; } private void save(final ResponseISO responseISO) { HibernateUtil.doInTransaction(new TransactionCallAble() {
public Integer call(Session session) throws Exception {;
return null;

public int prepareForAbort(long id, Serializable context) {
return ABORTED;


Thats all my post about Integrating Hibernate and jPOS Framework. Thank you for coming to my blog.

4 responses to “Integrating Hibernate and jPOS Framework”

  1. sada Avatar

    where is the project download link?

    1. dani Avatar

      you can download the project here: …???

  2. mack Avatar

    Please help out with new full setup tutorial to use hibernate in jpos

    1. didikhari Avatar

      you can use jpos EE hibernate module.

Leave a Reply

Your email address will not be published. Required fields are marked *