anthony wrote:
this is only my POV:
You should stop thinking in SQL update, insert, delete but focus on lifecycle semantics. Your DAO should offer:
- querying
- attaching modified
- attaching unmodified(with a specific lockmode)
- persisting (making persistent)
- deleting (making transient)
- detaching (making detached)
Anthony,
This actually helps quite a bit. I have been locked into the JDBC world for a while, and so I'm paranoid about isolation - I want to make sure that NO DB specific problems leak through the DAO layer...
When you're using a tool such as hibernate which already deals with DB isolation, your data access layer doesn't need to do this anymore. You can "feel free" to expose methods in your DAO's that are in fact "hibernate specific" like lock(), and as you say, detaching, and attaching objects, which are not normally found in a typcial DAO.
I'll have to get used to the hibernate way of thinking, and not restrict myself to the strict DOA rules I was following before.
I trust this is your message :-)
As to whether to use a DAO for each object, or one for each package, or even one layer for everything is a different topic I think. This depends on the size of the project, and the number of developers sharing code in my opinion.
For the short term, I'm happy just to get hibernate "shoe-horned" into our existing DAO framework.
Thanks!
Mal.
p.s. Do you do your transaction management calls in HibernateUtil, or in your DAO base classes? I'm still trying to find my "favourite" place to do this.