jpa - Why can't I catch EJB exceptions? -
i can't seem catch exceptions such noresultexception or ejbexception in java ee 6 project. there doing wrong? have caught exceptions outside ejb container first time using ejb. thanks.
@stateless public class userejb { @persistencecontext entitymanager em; public string getusername(user user) { return user.getname(); } public user fetchuserbyemail(string email) { user user = em.createnamedquery("user.findbyemail", user.class).setparameter("email", email).getsingleresult(); return user; } public user fetchuserbyid(int id) { return em.createnamedquery("user.findbyuserid", user.class).setparameter("userid", id).getsingleresult(); } public list<user> fetchallusers() { return em.createnamedquery("user.findall", user.class).getresultlist(); } } @named(value = "usercontroller") @requestscoped public class usercontroller { private user user = new user(); @ejb userejb userejb; @inject securitycontroller securitycontroller; public usercontroller() { } public void login(actionevent event) { try { user userlogin = userejb.fetchuserbyemail(user.getemail()); } catch (exception e) { } if (userlogin.getpassword().equals(user.getpassword())) { securitycontroller.setisloggedin(true); securitycontroller.setisadmin(true); securitycontroller.setuser(user); } } /** * @return user */ public user getuser() { return user; } /** * @param user user set */ public void setuser(user user) { this.user = user; }
what if put 2 system.out.printlns in code? 1 in exception handler , 1 right before if statement. get?
looking @ code would able catch exception, should jpa exception wrapped in ejb one.
Comments
Post a Comment