I am quite new in Hibernate. I managed to learn myself a bit about Hibernate but the biggest problem I have is a designing problem. I use Hibernate with Spring, which is responsible for transactions and JSF, which I use in presentation layer. I use entities which represent database records and DAOs which implement database operations (one public DAO's method == a database transaction). I use also Spring's OpenSessionInViewFilter so in my application one Hibernate Session is connected with one HTTP request, so the objects I return from business layer to presentation layer are connected to the session during all one HTTP request. Consider please example like this:
Presentation layer code (the business one is obvious I suppose):
Code:
...
User user1 = userDAO.get(1); //user login is "aaa"[code]
User user2 = userDAO.get(2);
user1.setLogin("bbb");
userDAO.makeSthWithThisObjectInTransaction(user2);
user1.setLogin("ccc");
...
After executing: the user1's login is bbb, because the changes made in persistent user1 object were committed during userDAO.makeSthWithThisObjectInTransaction(user2) method, after that user1 object is still attached to the session but no flush and commit operations are invoked.
I would prefer to invoke changes from presentation layer in more explicit way, because it works a bit sloppy now
Thanks for any help.
Best regards
Melmack