[英]Unable to retrieve EntityManagerFactory for unitName
When I try to reach a specific endpoint I get an exception saying "Unable to retrieve EntityManagerFactory for unitName parent_module " 当我尝试访问特定端点时,我得到一个异常,说“无法检索unitName parent_module的EntityManagerFactory”
However, I get this error since I structured the project on modules. 但是,由于我在模块上构建项目,因此出现此错误。 When I had everything in the parent module, and had the packaging tag as war, it worked without any errors.
当我拥有父模块中的所有内容,并将包装标签作为战争时,它的工作没有任何错误。
When I structured the project on modules, and made the parent packaging tag as pom, and the child module as war, I started to have the described exception. 当我在模块上构建项目,并将父包装标记作为pom,并将子模块作为war时,我开始具有所描述的异常。
Please note that I have the persistence.xml in the right path. 请注意,我在正确的路径中有persistence.xml。
CHILD_MODULE/src/main/resources/META-INF/persistence.xml CHILD_MODULE / src目录/主/资源/ META-INF / persistence.xml中
anyway, the configuration should be good, as long as it works perfectly if I move the files in the parent module. 无论如何,配置应该是好的,只要它在父模块中移动文件时效果很好。
The persistence.xml is present in the target folder at the execution time. persistence.xml在执行时出现在目标文件夹中。
I have tried annotating the EntityManager like @PersistenceContext(unitName = "parent_module"), but i get the same exception. 我试过像@PersistenceContext一样注释EntityManager(unitName =“parent_module”),但是我得到了同样的例外。
persistence.xml persistence.xml中
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="parent_module"
transaction-type="JTA">
<jta-data-source>jdbc/postgres.myproject</jta-data-source>
<mapping-file>META-INF/core-entity-mappings.xml</mapping-file>
</persistence-unit>
</persistence>
public abstract class AbstractAccessBA {
@PersistenceContext
protected EntityManager entityManager;
/**
* Flush all changes from the entity manager to the database
*/
public void flush() {
entityManager.flush();
}
}
public class WorkAccessBA extends AbstractAccessBA {
@Inject
private WorkMapper workMapper;
/**
* Finds all the entries
* @return a list of workBE
*/
public List<WorkBE> findAll() {
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<WorkBE> cq = cb.createQuery(WorkBE.class);
Root<WorkBE> rootEntry = cq.from(WorkBE.class);
CriteriaQuery<WorkBE> all = cq.select(rootEntry);
TypedQuery<WorkBE> allQuery = entityManager.createQuery(all);
return allQuery.getResultList();
}
It should return a list of all the result founded(Again, this works if I move all the files in the parent module), but when I move the files(configuration in the child module, which has a packaging tag "war", it returns me the error described. 它应该返回所有结果的列表(再次,如果我移动父模块中的所有文件,这是有效的),但是当我移动文件时(子模块中的配置,其具有包装标签“war”),返回我描述的错误。
"Unable to retrieve EntityManagerFactory for unitName parent_module " “无法为unitName parent_module检索EntityManagerFactory”
Found the answer myself. 我自己找到了答案。 The problem was in glassfish/domains/nameOftheDomain/applications
问题出在glassfish / domains / nameOftheDomain / applications中
There was the parent_module SNAPSHOT that I used to deploy it as war before structuring the application with parent-children modules. 在使用parent-children模块构建应用程序之前,我曾使用parent_module SNAPSHOT将其部署为war。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.