• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Where to use persist and transaction

 
Mathias Nilsson
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi! I'm pretty new to Hibernate!

Where do I do begin transactio, commit? Should this be done in every method in my DAO or where should I handle these things? Inside the DAO or outside?
 
dennis zined
Ranch Hand
Posts: 330
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi!

if you're using spring with hibernate, I would recommend an aop approach where you can configure transaction interceptors via xml. for example, remember the sample service code from your previous post? as persistent service methods are invoked, you can configure interceptors to catch these method calls and start a transaction and when the method calls end successfully you can commit a transaction. you can also specify the type of exceptions for the transaction manager to rollback if such exceptions were thrown. having an aop approach makes your code cleaner as all these transaction stuff are xml configured. and if you indeed use aop, you also have the flexibility of configuring other interceptors like logging, security, hibernate session, performance monitors, etc. without messing your code.

lookup 'aop' on how to use it...and theres always a java rancher ready to help out if you're lost. hope this helps and good luck
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic