Using a JTA persistence context without setting hibernate.transaction.jta.platform

GMan1973 picture GMan1973 · Mar 19, 2015 · Viewed 8.6k times · Source

I am updating an old application with as little re-programming as possible. I created a page similar to the old pages with just some test data to make sure I can create the link with the ejb / jpa and I am running into a problem. I will post the jsp, persistence.xml, and the error. After researching the web I still don't understand what the problem is or how to fix it. Thank you.

jsp

<%@ page import="com.ray.adt.model.Gridmaster" %>
<jsp:useBean id="GridMasterBean" scope="page" class="com.ray.adt.ejb.grid.GridMasterBean"/>
<%
System.out.println ("Start")    ;
String gridid = request.getParameter("gridid");
System.out.println ("String id is " + gridid);
Gridmaster master = null;
Integer gridInteger = Integer.parseInt(gridid);
master = GridMasterBean.findGrid(gridInteger);
String title = "None";
title =  master.getProgram();
System.out.println ("title is " + title);
%>
<html>
TEST PAGE

</html> 

persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
 <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
 <persistence-unit name="Grid-Persistence" transaction-type="JTA">
 <provider>org.hibernate.ejb.HibernatePersistence</provider>
 <jta-data-source>java:/DefaultDS</jta-data-source>
 <exclude-unlisted-classes>false</exclude-unlisted-classes>
 <properties>
 <property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.JTATransactionFactory"/>
 <property name="hibernate.hbm2ddl.auto" value="validate"/>
 </properties>
 </persistence-unit>
 </persistence>

error:

19:04:41,195 INFO  [stdout] (default task-42) Start

19:04:41,195 INFO  [stdout] (default task-42) String id is 2

19:04:41,212 INFO  [org.hibernate.jpa.internal.util.LogHelper] (default task-42) HHH000204: Processing PersistenceUnitInfo [
    name: Grid-Persistence
    ...]
19:04:41,215 WARN  [org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl] (default task-42) HHH000193: Overriding hibernate.transaction.factory_class is dangerous, this might break the EJB3 specification implementation
19:04:41,227 INFO  [org.hibernate.dialect.Dialect] (default task-42) HHH000400: Using dialect: org.hibernate.dialect.Oracle10gDialect
19:04:41,233 INFO  [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (default task-42) HHH000397: Using ASTQueryTranslatorFactory
19:04:41,237 INFO  [org.hibernate.tool.hbm2ddl.SchemaValidator] (default task-42) HHH000229: Running schema validator
19:04:41,237 INFO  [org.hibernate.tool.hbm2ddl.SchemaValidator] (default task-42) HHH000102: Fetching database metadata
19:04:41,692 WARN  [org.hibernate.jpa.internal.EntityManagerFactoryRegistry] (default task-42) HHH000436: Entity manager factory name (Grid-Persistence) is already registered.  If entity manager will be clustered or passivated, specify a unique value for property 'hibernate.ejb.entitymanager_factory_name'
19:04:41,693 ERROR [io.undertow.request] (default task-42) UT005023: Exception handling request to /ADTF/ShowData.jsp: org.apache.jasper.JasperException: javax.persistence.PersistenceException: Using a JTA persistence context wo setting hibernate.transaction.jta.platform
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:410) [jastow-1.0.0.Final.jar:1.0.0.Final]
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:326) [jastow-1.0.0.Final.jar:1.0.0.Final]
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259) [jastow-1.0.0.Final.jar:1.0.0.Final]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final]
    at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
    at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:113) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:61) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
    at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:240) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:227) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:73) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:146) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.server.Connectors.executeRootHandler(Connectors.java:177) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:727) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.7.0_71]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.7.0_71]
    at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_71]
Caused by: javax.persistence.PersistenceException: Using a JTA persistence context wo setting hibernate.transaction.jta.platform
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.markForRollbackOnly(AbstractEntityManagerImpl.java:1538) [hibernate-entitymanager-4.3.5.Final.jar:4.3.5.Final]
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1686) [hibernate-entitymanager-4.3.5.Final.jar:4.3.5.Final]
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:1132) [hibernate-entitymanager-4.3.5.Final.jar:4.3.5.Final]
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:1068) [hibernate-entitymanager-4.3.5.Final.jar:4.3.5.Final]
    at com.ray.adt.ejb.DatabaseUtilityBean.findEntity(DatabaseUtilityBean.java:114) [ADTF_EJB.jar:]
    at com.ray.adt.ejb.grid.GridMasterBean.findGrid(GridMasterBean.java:29) [ADTF_EJB.jar:]
    at org.apache.jsp.ShowData_jsp._jspService(ShowData_jsp.java:71)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:69) [jastow-1.0.0.Final.jar:1.0.0.Final]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final]
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:366) [jastow-1.0.0.Final.jar:1.0.0.Final]
    ... 29 more

Answer

martins.tuga picture martins.tuga · Mar 28, 2015

You have to add the following line to your persistence.xml

If you are using Glassfish:

<property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.SunOneJtaPlatform" />

If you are using JBoss:

<property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform" />

This should solve your problem.