• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic