我尝试在9.0.0版本中启动TomEE服务器并部署一个简单的Web应用程序。
我使用Hibernate 6.2.2作为jpa和postgres的提供者
当我部署.war时,它给了我这些错误(堆栈很长,我只是把严重的):
SEVERE [http-nio-8080-exec-3] jdk.internal.reflect.NativeMethodAccessorImpl.invoke Error destroying child org.apache.catalina.LifecycleException: An invalid Lifecycle transition was attempted ([before_destroy]) for component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/servlet-jsp-jdbc-jpa]] in state [STARTING_PREP]
---------------------
SEVERE [http-nio-8080-exec-3] org.apache.openejb.assembler.classic.Assembler.destroyApplication undeployException original cause java.lang.Exception: deployment not found: servlet-jsp-jdbc-jpa.Comp669096535
-------------------------
SEVERE [http-nio-8080-exec-3] org.apache.openejb.assembler.classic.Assembler.destroyApplication undeployException original cause java.lang.Exception: persistence-unit: pu 1912458056localhost: Name "openejb/PersistenceUnit/pu 1912458056localhost" not found.
....
Caused by: javax.naming.NameNotFoundException: Name "openejb/PersistenceUnit/pu 1912458056localhost" not found.
---------------------------
SEVERE [http-nio-8080-exec-3] org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal Unable to deploy collapsed ear in war StandardEngine[Catalina].StandardHost[localhost].StandardContext[/servlet-jsp-jdbc-jpa] org.apache.openejb.OpenEJBException: Creating application failed: C:\apache-tomee-microprofile-9.0.0\webapps\servlet-jsp-jdbc-jpa: UUID
..........
Caused by: java.lang.NoSuchFieldError: UUID
----------------------------
SEVERE [http-nio-8080-exec-3] jdk.internal.reflect.NativeMethodAccessorImpl.invoke Error deploying web application archive [C:\apache-tomee-microprofile-9.0.0\webapps\servlet-jsp-jdbc-jpa.war] java.lang.IllegalStateException: Error starting child
........
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/servlet-jsp-jdbc-jpa]] ..............
Caused by: org.apache.tomee.catalina.TomEERuntimeException: org.apache.openejb.OpenEJBException: Creating application failed: C:\apache-tomee-microprofile-9.0.0\webapps\servlet-jsp-jdbc-jpa: UUID
.........
Caused by: org.apache.openejb.OpenEJBException: Creating application failed: C:\apache-tomee-microprofile-9.0.0\webapps\servlet-jsp-jdbc-jpa: UUID
..........
Caused by: java.lang.NoSuchFieldError: UUID
.........
结构为:
- 网络应用程序
- META-INF
- persistence.xml
- context.xml
- WEB-INF
- web.xml
classes(我把所有编译好的类放在这里)
- lib
- hibernate-core-6.2.2.Final.jar
- index.html
persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.2"
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">
<!-- NO JNDI -->
<persistence-unit name="pu" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<properties>
<property name="jakarta.persistence.jdbc.driver" value="org.postgresql.Driver"/>
<property name="jakarta.persistence.jdbc.url" value="jdbc:postgresql://localhost/MVC?currentSchema=public&ssl=false"/>
<property name="jakarta.persistence.jdbc.user" value="******"/>
<property name="jakarta.persistence.jdbc.password" value="********"/>
<property name="hibernate.show_sql" value="true" />
</properties>
</persistence-unit>
</persistence>
context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/servlet-jsp-jdbc-jpa" >
</Context>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<display-name>servlet_jsp_jdbc_jpa</display-name>
</web-app>
这些是使用持久化单元的类
package jpa;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.Persistence;
import jakarta.persistence.PersistenceUnit;
public class PersistenceManager {
//@PersistenceUnit(unitName="JTA-pu")
private static final EntityManagerFactory emf;
static {
emf = Persistence.createEntityManagerFactory("pu");
}
private PersistenceManager() {
}
public static EntityManagerFactory getEmf() {
return emf;
}
}
package filters;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.PersistenceContext;
import jakarta.persistence.PersistenceUnit;
import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import jakarta.servlet.http.HttpFilter;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jpa.PersistenceManager;
import java.io.IOException;
@WebFilter(value="/*")
public class SessionBinderFilter extends HttpFilter {
// @PersistenceUnit(unitName="JTA-pu")
private EntityManagerFactory emf = PersistenceManager.getEmf();
// @PersistenceContext(unitName="JTA-pu")
private EntityManager em = emf.createEntityManager();
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
if (!(request instanceof HttpServletRequest) || !(response instanceof HttpServletResponse)) {
throw new ServletException("non-HTTP request or response");
}
request.setAttribute("EntityManager", em);
filterChain.doFilter(request, response);
if (em.isOpen()) {
em.close();
}
}
}
我不能理解这个问题,因为我是相当新的jpa和我搜索了很多,但我没有找到任何东西。
我也尝试了JTA和RESOURCE_LOCAL与JNDI,但没有工作,问题是一样的。
任何建议或信息是赞赏
1条答案
按热度按时间7eumitmz1#
TomEE 9.0.0与Jakarta EE 9.1兼容,后者包括JPA 3.0。
Hibernate 6.2.x实现了包含API changes such as introducing UUID generators的JPA 3.1。
这些规范更改不包括在API shade中,该API shade在TomEE 9中使用。要解决这个问题,您需要将Hibernate降级到符合JPA 3.0的6.1系列。