我正在创建EJB项目。对于服务器我使用Wildfly 8.2,对于数据库I使用XAMPP。我有EJB项目,用于会话管理器(接口和实现),用于表的实体的JPA项目,用于servlet和jsp页面的动态web项目。我试图从数据库中获取一些数据时遇到问题。例外:
23:50:20,901 ERROR [org.jboss.as.ejb3.invocation] (default task-3) JBAS014134: EJB Invocation failed on component BazenSessionManager for method public abstract model.Vlasnik sessions.BazenSessionManagerLocal.loginVlasnik(java.lang.String,java.lang.String): javax.ejb.EJBException: javax.persistence.NoResultException: No entity found for query
引起:
Caused by: javax.persistence.NoResultException: No entity found for query
at org.hibernate.jpa.internal.QueryImpl.getSingleResult(QueryImpl.java:498) [hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final]
at sessions.BazenSessionManager.loginVlasnik(BazenSessionManager.java:40) [BazenEJB.jar:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0_25]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [rt.jar:1.8.0_25]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.8.0_25]
at java.lang.reflect.Method.invoke(Method.java:483) [rt.jar:1.8.0_25]
at org.jboss.as.ee.component.ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptor.java:52)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)
at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:63)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:407)
at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.doMethodInterception(Jsr299BindingsInterceptor.java:82) [wildfly-weld-8.2.0.Final.jar:8.2.0.Final]
at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.processInvocation(Jsr299BindingsInterceptor.java:93) [wildfly-weld-8.2.0.Final.jar:8.2.0.Final]
at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:63)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)
at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:63)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
at org.jboss.as.ejb3.component.invocationmetrics.ExecutionTimeInterceptor.processInvocation(ExecutionTimeInterceptor.java:43) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
at org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:47) [wildfly-jpa-8.2.0.Final.jar:8.2.0.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:407)
at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:55) [weld-core-impl-2.2.6.Final.jar:2014-10-03 10:05]
at org.jboss.as.weld.ejb.EjbRequestScopeActivationInterceptor.processInvocation(EjbRequestScopeActivationInterceptor.java:83) [wildfly-weld-8.2.0.Final.jar:8.2.0.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
at org.jboss.as.ee.concurrent.ConcurrentContextInterceptor.processInvocation(ConcurrentContextInterceptor.java:45) [wildfly-ee-8.2.0.Final.jar:8.2.0.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:53)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
at org.jboss.as.ejb3.component.interceptors.NonPooledEJBComponentInstanceAssociatingInterceptor.processInvocation(NonPooledEJBComponentInstanceAssociatingInterceptor.java:59) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:273) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
... 62 more
peristence标记下的内容:
<persistence-unit name="BazenEAR">
<jta-data-source>java:jboss/datasources/mysql</jta-data-source>
<class>model.Izvestaj</class>
<class>model.Neregularnost</class>
<class>model.Plivac</class>
<class>model.Poruka</class>
<class>model.Skola</class>
<class>model.Spasilac</class>
<class>model.Termin</class>
<class>model.Trener</class>
<class>model.Vlasnik</class>
</persistence-unit>
BazenEAR是包含JPA项目,EJB项目和JPA项目的EAR项目的名称。 model.Vlasnik ..是类的package.name,它是使用选项Generate entities from tables自动生成的。 Vlasnik.java
@Entity
@Table(name="Vlasnik")
@NamedQuery(name="Vlasnik.findAll", query="SELECT v FROM Vlasnik v")
public class Vlasnik implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private int idvlasnika;
private String email;
private String ime;
private String lozinka;
private String prezime;
//bi-directional many-to-one association to Izvestaj
@OneToMany(mappedBy="vlasnik")
private List<Izvestaj> izvestajs;
//bi-directional many-to-one association to Neregularnost
@OneToMany(mappedBy="vlasnik")
private List<Neregularnost> neregularnosts;
//bi-directional many-to-one association to Poruka
@OneToMany(mappedBy="vlasnik")
private List<Poruka> porukas;
public Vlasnik() {
}
public int getIdvlasnika() {
return this.idvlasnika;
}
public void setIdvlasnika(int idvlasnika) {
this.idvlasnika = idvlasnika;
}
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
public String getIme() {
return this.ime;
}
public void setIme(String ime) {
this.ime = ime;
}
public String getLozinka() {
return this.lozinka;
}
public void setLozinka(String lozinka) {
this.lozinka = lozinka;
}
public String getPrezime() {
return this.prezime;
}
public void setPrezime(String prezime) {
this.prezime = prezime;
}
public List<Izvestaj> getIzvestajs() {
return this.izvestajs;
}
public void setIzvestajs(List<Izvestaj> izvestajs) {
this.izvestajs = izvestajs;
}
public Izvestaj addIzvestaj(Izvestaj izvestaj) {
getIzvestajs().add(izvestaj);
izvestaj.setVlasnik(this);
return izvestaj;
}
public Izvestaj removeIzvestaj(Izvestaj izvestaj) {
getIzvestajs().remove(izvestaj);
izvestaj.setVlasnik(null);
return izvestaj;
}
public List<Neregularnost> getNeregularnosts() {
return this.neregularnosts;
}
public void setNeregularnosts(List<Neregularnost> neregularnosts) {
this.neregularnosts = neregularnosts;
}
public Neregularnost addNeregularnost(Neregularnost neregularnost) {
getNeregularnosts().add(neregularnost);
neregularnost.setVlasnik(this);
return neregularnost;
}
public Neregularnost removeNeregularnost(Neregularnost neregularnost) {
getNeregularnosts().remove(neregularnost);
neregularnost.setVlasnik(null);
return neregularnost;
}
public List<Poruka> getPorukas() {
return this.porukas;
}
public void setPorukas(List<Poruka> porukas) {
this.porukas = porukas;
}
public Poruka addPoruka(Poruka poruka) {
getPorukas().add(poruka);
poruka.setVlasnik(this);
return poruka;
}
public Poruka removePoruka(Poruka poruka) {
getPorukas().remove(poruka);
poruka.setVlasnik(null);
return poruka;
}
来自sessionmanager类的loginVlasnik方法:
@Override
public Vlasnik loginVlasnik(String email, String password) {
Vlasnik vlasnik =(Vlasnik) entityManager.createQuery("select v from Vlasnik v where v.email like :email").setParameter("email", email).getSingleResult();
if (vlasnik != null && vlasnik.getLozinka().equals(password)) {
return vlasnik;
} else {
return null;
}
}
表vlasnik:
(IDVLASNIKA, IME, PREZIME, EMAIL, LOZINKA, primary key (IDVLASNIKA)
LoginVlasnik servlet(没有导入部分):
@WebServlet("/LoginVlasnik")
public class LoginVlasnik extends HttpServlet {
private static final long serialVersionUID = 1L;
@EJB
BazenSessionManagerLocal sessionManager;
public LoginVlasnik() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String message = "";
String page = "";
String email = request.getParameter("email");
String password = request.getParameter("password");
Vlasnik vlasnik = sessionManager.loginVlasnik(email, password);
if (vlasnik != null) {
message = "Uspesno ste prijavljeni";
page = "vlasnik.jsp";
request.setAttribute("message", message);
RequestDispatcher rd = request.getRequestDispatcher(page);
rd.forward(request, response);
} else {
message = "Morate se prvo registrovati.";
page = "register.jsp";
request.setAttribute("message", message);
RequestDispatcher rd = request.getRequestDispatcher(page);
rd.forward(request, response);
}
}
}
我在调用servlet的JSP页面:
<div>
<h3>Prijava vlasnika:</h3>
<form action="LoginVlasnik" method="post">
... fields for "email" and "lozinka"
</form
你知道这里发生了什么吗?我错过了什么吗? EAR的部署是成功的,我运行应用程序,当我点击&#34; Prijavi me&#34;按钮,出现以下错误。