I think this answer is pretty much what I want. But I still got a question about the EntityManager. Can we inject a Session (Hibernate session) and how to do that? How the session can be managed? Or I am absolutely wrong?
On 12 May 2011 13:41, ale <[email protected]> wrote: > ------------ CLIENT SIDE ------------ > > class View { > uiBinder().... > } > > class Presenter { > onbind() { > newUserButton() { > dispatch(new NewUserAction("name", "lastname"), ...); > } > } > } > *Clear* > > ------------ SERVER SIDE ------------ > > class NewUserActionHandler { > private final UserService userService; > > @Inject > public NewUserActionHandler(UserService userService) { > this.userService = userService; > } > > public NewUserResult execute(NewUserAction action, ...) { > this.userService.createNewUser(action.getName(), > action.getLastName()); > } > ... > } > *Clear* > > class UserService { > private final UserDao userDao; > > @Inject > UserService(UserDao userDao) { > this.userDao = userDao; > } > > Long createNewUser(String name, String lastName) { > return userDao.storeUser( new User(name, lastName)); > } > > } > *Clear* > > class UserDao { > private final Provider<EntityManager> em; > > @Inject > public UserDao(Provider<EntityManager> em) { > this.em = em; > } > > public Long storeUser(User user) { > this.em.get().persist(user); > return user.getId(); > } > } > I do not understand this one here. Suppose my UserDao inherited from a GenericDao. So the inherited store method looks like ... public T store (T entity) { getSession().saveOrUpdate(entity); return entity.getId(); } ... protected Session getSession() { return this.session } protected void setSession(Session s) { this.session = s; } ... also the UserDao's constructor will be looks like @Inject public UserDao(Session s) { setSession(s); } Sorry I am really confused, and I may absolutely wrong. I am wondering here how the session could be correctly injected/managed if this is feasible. Thanks. > > On May 10, 4:02 am, Bin Wu <[email protected]> wrote: > > Hello everyone, > > > > I am pretty new to Guice and even J2EE, and I am currently trying to > build a > > webapp which ues (GWT, Google-gin, gwt-platform, Guice, Hibernate etc.). > My > > problem here is, at the server side, I am bit confused about how those > > components can collaborate with each other in a good manner. Anyone here > > has a good example which uses Guice, Hibernate and a DAO layer? > > > > Thanks a lot. > > -- > You received this message because you are subscribed to the Google Groups > "google-guice" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/google-guice?hl=en. > > -- Regards, Bin Wu | *BluePoint *| 03 9296 5100 | 0423 710 288 | *www.bluepoint.net.au*<http://www.bluepoint.net.au/> BluePoint has Gone *Google*! *Each day, thousands of companies are going Google by switching to Google Apps – a web-based suite of messaging and collaboration applications. It's all hosted by Google, and designed with security and reliability in mind, saving your company the frustrations and hassles of managing traditional IT solutions yourself.** Call BluePoint for more information or view the cloud calculator <http://www.gonegoogle.com> to calculate your potential business savings.* -- You received this message because you are subscribed to the Google Groups "google-guice" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
