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
classes (where i put all the compiled classes)
lib
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>
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
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.