• Post Reply Bookmark Topic Watch Topic
  • New Topic

Data not committing in database . Using Hibernate / Message Driven Bean/ Container Managed Transacti  RSS feed

apaar kaura
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am try to add a record in the database using Message Driven Bean. I am using Container Managed Transaction. The MDB's onMessage() picks the message from the queue processes it and further gives it to Business Logic implemented through another Stateless bean which is container manged.From this the data is saved in the database using Hibernate. The code in Hibernate is as follows:

private Session openSession() throws HibernateException {
SessionFactory sessionFactory = HibernateAbstractSessionFactory.getInstance()
session = sessionFactory.openSession();

return session;
public void addEmployee(EmployeeSearchDTO addDTO)
Exception {
Session session = null;
try {
//opening the session
session = openSession();
} catch (HibernateException ex) {
"Exception occurred while adding/updating the Zip Code",
} finally {
//This method is used to save the transaction and end the session
private void doFinally(Session session) throws Exception {

try {
} catch (HibernateException ex) {
"Hibernate Exception occurred while closing session", ex);

I have tried with Transaction type as Reqired / Not Supprted for my onMessage() & transaction type as Required for Business logic Bean.
If you will see the above code if I give session.connection().commit(); the record is commiting but this is bypsassing the Container Mangaged transactions capabilities and it is more of a work around. if I do not give this there is no error as such but then the record is also not committed.

Please help me with this issue.

It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!