英文:
TomEE 9 fails to load persistence unit with Hibernate 6.2 - NoSuchFieldError: UUID
问题
I'm sorry, but it seems that your request is too long to be processed in a single response. Please specify the specific parts or sections you would like me to translate for you, and I'll be happy to help with that.
英文:
I'm trying to start a TomEE server in version 9.0.0 and deploy a simple webapp.
I'm using Hibernate 6.2.2 as the provider for jpa and postgres
When i deploy the .war it gives me these errors (the stack is long i just put the severe):
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
.........
The structure is:
-
webapp
-
META-INF
-
persistence.xml
-
context.xml
-
-
WEB-INF
- web.xml
classes (where i put all the compiled 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&amp;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>
These are the classes that are using the persistence-unit
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();
}
}
}
I can t understand the problem because i'm quite new on jpa and i searched a lot but i didn t find anything.
I tried also with JTA and RESOURCE_LOCAL with JNDI but nothing works, the problem is the same.
Any suggest or information is appreciated
答案1
得分: 1
TomEE 9.0.0 兼容 Jakarta EE 9.1,其中包括 JPA 3.0。
Hibernate 6.2.x 实现了 JPA 3.1,其中包括 API 更改,如引入 UUID 生成器。
这些规范更改未包含在 TomEE 9 中使用的 API 约束中。要解决您的问题,您需要将 Hibernate 降级到其 6.1 系列,该系列与 JPA 3.0 兼容。
英文:
TomEE 9.0.0 is compatible with Jakarta EE 9.1, which includes JPA 3.0.
Hibernate 6.2.x implements JPA 3.1 which includes API changes such as introducing UUID generators.
These spec changes aren't included in the API shade, which is used in TomEE 9. To fix your issue, you need to downgrade Hibernate to it's 6.1 series, which complies with JPA 3.0.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论