我希望这次有人可以帮我解决这个问题。我正在开发一个使用EJB + JPA构建的Web应用程序,最后我得到的是错误消息:javax.ejb.EJBException并且这样的错误指向DAO本地接口中的第25行并且也在行中31在类i中将名为SessionLogin的com.javarevolutions.ejb.bean包放入EJB模块中。我的问题是为什么它说名为“Login.findByLoginAndPassword”的查询没有通过错误消息进行聚焦
引起:java.lang.NullPointerException
这是我的代码,以便更好地了解我的问题:
Caused by: javax.ejb.EJBException
at com.sun.ejb.containers.EJBContainerTransactionManager.processSystemException(EJBContainerTransactionManager.java:748)
at com.sun.ejb.containers.EJBContainerTransactionManager.completeNewTx(EJBContainerTransactionManager.java:698)
at com.sun.ejb.containers.EJBContainerTransactionManager.postInvokeTx(EJBContainerTransactionManager.java:503)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4475)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2009)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1979)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:220)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
at com.sun.proxy.$Proxy405.validaDatos(Unknown Source)
at com.javarevolutions.ejb.bean.__EJB31_Generated__SessionLogin__Intf____Bean__.validaDatos(Unknown Source)
at com.javarevolutions.jsf.bean.BeanLogin.validarLogin(BeanLogin.java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.el.parser.AstValue.invoke(AstValue.java:275)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
... 35 more
Caused by: java.lang.NullPointerException
at com.javarevolutions.ejb.dao.DAOLoginImpl.existUser(DAOLoginImpl.java:25)
at com.javarevolutions.ejb.bean.SessionLogin.validaDatos(SessionLogin.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1081)
at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1153)
at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:4695)
at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:630)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:582)
at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:46)
at sun.reflect.GeneratedMethodAccessor175.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:582)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doCall(SystemInterceptorProxy.java:163)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:140)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:369)
at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:4667)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4655)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:212)
... 50 more
提前感谢你能给我的暗示。
注意:这是我的第二个。我在论坛上发了询问,没有人给我一个答案,但我已经解决了最后一个问题。
:(
公共类DAOLoginImpl实现了DAOLogin {
@PersistenceContext
EntityManager em;
@Override
public boolean existUser(Login entity) {
Query query = em.createNamedQuery("Login.findByLoginAndPassword");
query.setParameter("usuario", entity.getUsuario());
query.setParameter("contrasenia", entity.getPassword());
if (query.getSingleResult() != null) {
return true;
}
return false;
}
}
@Stateless
@LocalBean 公共类SessionLogin {
public boolean validaDatos(VOLogin vo) {
System.out.println("User : " + vo.getUsuario());
System.out.println("Password : " + vo.getContrasenia());
DAOLogin dao = new DAOLoginImpl();
Login entity = new Login();
entity.setUsuario(vo.getUsuario());
entity.setPassword(vo.getContrasenia());
return dao.existUser(entity);
}
}
public Login() {
}
public Login(String usuario) {
this.usuario = usuario;
}
public Login(String usuario, String password, String nombre, int edad) {
this.usuario = usuario;
this.password = password;
this.nombre = nombre;
this.edad = edad;
}
public String getUsuario() {
return usuario;
}
public void setUsuario(String usuario) {
this.usuario = usuario;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
public int getEdad() {
return edad;
}
public void setEdad(int edad) {
this.edad = edad;
}
@Override
public int hashCode() {
int hash = 0;
hash += (usuario != null ? usuario.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Login)) {
return false;
}
Login other = (Login) object;
if ((this.usuario == null && other.usuario != null) || (this.usuario != null && !this.usuario.equals(other.usuario))) {
return false;
}
return true;
}
@Override
public String toString() {
return "com.javarevolutions.ejb.entities.Login[ usuario=" + usuario + " ]";
}
} 代码在这里
答案 0 :(得分:0)
正如您的代码所说,它是NullPointerException
,这意味着DAOLoginImpl
内的某个地方您尝试使用空对象。
Caused by: java.lang.NullPointerException
at com.javarevolutions.ejb.dao.DAOLoginImpl.existUser(DAOLoginImpl.java:25)
要使其正常工作,请确保在使用之前检查空对象。