On Thu, Aug 20, 2009 at 11:13 AM, Martin Gainty<mgai...@hotmail.com> wrote: > > cannot do a get(0) on a null result
Might be true, but it also demonstrates why method chaining can be troublesome, we don't know if the NPE is coming from there or from the call to getHibernateTemplate(), etc. I would suggest breaking this line into multiple lines. It will give you an indication whether you are still having wiring problems or if the NPE is caused from a lack of results on your query (as Martin is indicating). > > public User getUser(String userName) { > return (User)getHibernateTemplate().find("from User as u where > u.name = ?", userName).get(0); > }public interface UserService cannot be referenced directly so best to use > your impl class > > change User usr= userService.getUser(username); > to User usr=userServiceImp.getUser(username); > > traditionally implementation classes are named ClassNameImpl instead of > ClassNameImp Martin, that is just silly, it's a *good* practice to program to interfaces and leave yourself the ability to swap out implementations later... It's pretty much Spring 101. > > avoid static references such as userService.getUser(username); > better to > getUserService().getUser(username); > > //which means the *Action will need accessor method getUserService defined > e.g. > public UserServiceImp getUserService() { > return userService; > } > > Martin Gainty -- Wes Wannemacher Head Engineer, WanTii, Inc. Need Training? Struts, Spring, Maven, Tomcat... Ask me for a quote! --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org