无法修复 java.lang.IllegalStateException: 无法检索 EntityManagerFactory for unitName
我试图通过做一个项目来学习JSP和servlets。我的目标不是暂时不关注JPA,ORM和持久性,甚至EJB。所以,请不要告诉我要读一本关于它的教程或书。不幸的是,我不应该使用SQL查询来与数据库进行交互。相反,我使用预先编写的JPA代码来管理持久性,同时专注于jsp和servlet。
当我运行我的项目时,我收到错误 - 我的项目位于 - https://github.com/double-whammy/affablebean.git 下载为zip按钮位于右下角。java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName AffableBeanPU.
注意 - 我的持久性.xml文件位于 META-INF 文件夹中。我检查并再次构建了我的项目。因此,可以排除这种原因。
我用谷歌搜索,没有一个解决方案是有帮助的。如何修复此错误?
MyProject
|
|__java (src folder)
| |
| |__controller (package)
| | |__ControllerServlet.java
| |
| |__entity (entity classes here)
| |__session (facade classes for each entity class)
|
|
|__WebContent
|
|__WEB-INF
|
|__view
| |__category.jsp
| |
| |etc...
|
|__index.jsp
例外:
Time|Info: Redirecting to /index.jsf
Time|Info: Admin Console: Initializing Session Attributes...
Time|Warning: EJB5184:A system exception occurred during an invocation on EJB CategoryFacade,
method: public java.util.List session.AbstractFacade.findAll()
Time|Warning: 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.$Proxy193.findAll(Unknown Source)
at session.__EJB31_Generated__CategoryFacade__Intf____Bean__.findAll(Unknown Source)
at controller.ControllerServlet.init(ControllerServlet.java:31)
at javax.servlet.GenericServlet.init(GenericServlet.java:244)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1583)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:1212)
etc ................................................... etc...
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName AffableBeanPU
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.init(EntityManagerWrapper.java:138)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper._getDelegate(EntityManagerWrapper.java:171)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.getCriteriaBuilder(EntityManagerWrapper.java:834)
at session.AbstractFacade.findAll(AbstractFacade.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
etc ................................................... etc...
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:212)
... 33 more
Time|Severe: WebModule[/AffableBean]StandardWrapper.Throwable
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)
etc ................................................... etc...
at session.__EJB31_Generated__CategoryFacade__Intf____Bean__.findAll(Unknown Source)
at controller.ControllerServlet.init(ControllerServlet.java:31)
at javax.servlet.GenericServlet.init(GenericServlet.java:244)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1583)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:1212)
etc ................................................... etc...
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName AffableBeanPU
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.init(EntityManagerWrapper.java:138)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper._getDelegate(EntityManagerWrapper.java:171)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.getCriteriaBuilder(EntityManagerWrapper.java:834)
at session.AbstractFacade.findAll(AbstractFacade.java:41)
etc ................................................... etc...
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:212)
... 33 more
Time|Warning: StandardWrapperValve[ControllerServlet]: Allocate exception for servlet ControllerServlet
java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName AffableBeanPU
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.init(EntityManagerWrapper.java:138)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper._getDelegate(EntityManagerWrapper.java:171)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.getCriteriaBuilder(EntityManagerWrapper.java:834)
at session.AbstractFacade.findAll(AbstractFacade.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
etc ................................................... etc...
持久性.xml :
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="AffableBeanPU"
transaction-type="JTA">
<jta-data-source>jdbc/affablebean</jta-data-source>
<properties>
<property name="eclipselink.logging.level" value="FINEST" />
</properties>
</persistence-unit>
</persistence>