• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
apaar kaura
Greenhorn
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()
.getSessionFactory();
session = sessionFactory.openSession();

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

try {
session.flush();
session.connection().commit();
session.close();
} catch (HibernateException ex) {
ExceptionHelper.throwDataException(
"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.

Regards
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic