我正在制作一个Maven EJB模块,当我使用JUnit和Embedded GlassFish容器运行测试时,我遇到了麻烦。 EJB模块由JPA实体和EJB无状态会话bean组成。
整个项目可以在这里找到 https://github.com/muhamed-hassan/service-layer
的persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="custmgr-pu" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/customerCM_PU</jta-data-source>
<class>model.Customer</class>
<properties>
<property name="eclipselink.target-database" value="MySQL"/>
<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
<property name="eclipselink.logging.level" value="ALL"/>
</properties>
</persistence-unit>
</persistence>
我遇到了这种异常
`java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName custmgr-pu`
请注意,我将persistence.xml文件放在src / main / resources / META-INF目录下,因为我正在使用maven ejb项目。