3
我似乎無法在我的java ee 6項目中捕獲異常,如NoResultException或EJBException。有什麼我做錯了嗎?我在EJB容器外捕獲了異常,但這是我第一次使用EJB。謝謝。爲什麼我無法捕獲EJB異常?
@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 the user
*/
public User getUser() {
return user;
}
/**
* @param user the user to set
*/
public void setUser(User user) {
this.user = user;
}
你怎麼知道異常不會拋出,當你趕上`Exception`並且不記錄它? catch(Exception e){}嘗試編寫`e.printStacktrace()` – 2010-12-06 13:40:03
您能夠在這裏添加來自glassfish日誌的堆棧跟蹤嗎? – 2010-12-18 04:55:11