0
votes

I'm using jboss 4.2 with Hibernate. i need to log transactions duration, so I have statistics on the average time it takes a transaction to complete or rollback. another issue I have is jboss JTA (arjuna) aborting long running transactions, so I need to know what timeout to configure there.

1
What is your Hibernate version? Some versions of Hibernate can gather statistics themselves. Or you can use an AOP framework.Amir Pashazadeh
Hibernate version is 3.0erezul

1 Answers

0
votes

I think you should create a timer that will count the time between the transaction start and end. A possibility to achieve this can be:


EntityManager em = HibernateUtil.createEntityManager(); //I used JPA's EntityManager instead of hibernate's sessions. createEntityManager iss a function created by you.
EntityTransaction tx = em.getTransaction();
tx.begin();
Date startDate = new Date();

//... your DB stuff goes here ...

tx.commit();
Date endDate = new Date();

MyLogger.logTransactionDuration(startDate, endDate);

In the above snippet of code, I make you the idea of how you can achieve this.

If you want, you can use log4j or slf4j api, and you would to make only some settings in log4j.properties file.

Hope to help.