Hi all.
I just barely started using Hibernate and ran into the following problem.
I have data, business, and presentation layers. Data layer classes are generated automatically and present simple "bean" classes. We then create business classes ourselves. Presentation layer calls query methods from the business classes. A session is opened and closed every time a business object method is executed. Also, business object just delegates method calls to the incapsulated data object.
The problem is with the save() method of the business class. I want this method to work with both persistent and newly created objects. However, if I use session.update(DO) it chockes on insertions, and if I use session.save(DO) it chokes on updates. When I try to use session.saveOrUpdate(DO) then if a table has a composite primary key it always tries to insert a new row, even if the object already persists in the database.
What is the right way to implement data/business/presentation architecture? Should I use different methods for saving persistent and newly created objects? If yes, then how can I determine whether an object persists in the database or not?
Thank you.
Oleg
|