agreed..i would also suggest wrap the code in try catch for the NullPointerException
good call wes! Martin Gainty ______________________________________________ Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen. Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni. > Date: Thu, 20 Aug 2009 11:21:31 -0400 > Subject: Re: Hibernate3+Spring2.5+Struts2 > From: w...@wantii.com > To: user@struts.apache.org > > 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 > _________________________________________________________________ Hotmail® is up to 70% faster. Now good news travels really fast. http://windowslive.com/online/hotmail?ocid=PID23391::T:WLMTAGL:ON:WL:en-US:WM_HYGN_faster:082009