-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: UserDAO patter in Hibernate in Action
PostPosted: Tue Mar 22, 2005 2:12 pm 
Beginner
Beginner

Joined: Fri Mar 12, 2004 5:18 pm
Posts: 44
In Hibernate in Action, it recommends to create a DAO object and when I want to save a persistent object, it should be saved like this.

However, isn't it better to have just 1 save method in HibernateUtil where it handles all the begin/close/commit transaction?

What is the drawback of that approach?


from:

Code:

UserDAO userDAO = new UserDAO();
User u1 = new User("Christian", "Bauer", "turin", "abc123", "christian@hibernate.org");
userDAO.makePersistent(u1);
HibernateUtil.commitTransaction();
HibernateUtil.closeSession();


to:
Code:
HibernateUtil.save(u1);
// where HibernateUtil.save() is this:
HibernateUtil.save(User u1) {
HibernateUtil.beginTransaction();
HibernateUtil.getSession().saveOrUpdate(u1);
HibernateUtil.commitTransaction();
HibernateUtil.closeSession();
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 22, 2005 3:05 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
You can design this in whatever way you like. The advantages and disadvantes should be very trival to spot, even for a beginner and esp. after you have read the section about DAOs. If you still don't know what to do, post in the regular Hibernate user forum.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.