Glassfish异常:使用JTA时无法使用EntityTransaction

时间:2015-03-13 10:40:08

标签: java webserver glassfish-3 application-server


我有一个例外:

java.lang.IllegalStateException: Exception Description: Cannot use an EntityTransaction while using JTA.

我的项目不是EJB,而是GWT项目。 我阅读了许多主题clickclickclick,主题相同,但没有结果......
我使用Glassfish Installed Version: GlassFish v3 (build 74.2) 我的persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         version="1.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_1_0.xsd">
<persistence-unit name="fpkmPU" transaction-type="JTA">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>jdbc/fpkmDB</jta-data-source>
    <class>...</class>
    ...
    <properties>
        <property name="eclipselink.target-server" value="SunAS9"/>
        <property name="eclipselink.target-database" value="Oracle"/>
        <property name="eclipselink.logging.level" value="WARNING"/>
        <property name="eclipselink.ddl-generation" value="none"/>
        <property name="eclipselink.jdbc.cache-statements" value="true"/>
        <property name="eclipselink.jdbc.cache-statements.size" value="100"/>
        <property name="eclipselink.jdbc.batch-writing" value="JDBC"/>
        <property name="eclipselink.jdbc.batch-writing.size" value="1000"/>
        <property name="eclipselink.jdbc.property.defaultRowPrefetch" value="1000"/>
        <property name="eclipselink.transaction.join-existing" value="true"/>
    </properties>
</persistence-unit>

代码中抛出的异常:

ParametrizedEntityManager em = persistenceService.getEntityManager();
    if (em == null) {
        throw new NullPointerException("Entity Manager is null!");
    }
    EntityTransaction tx = null;
    try {
        tx = em.getTransaction();    //exception is here
        ...
    } catch(...){
    }

如果我从代码中删除EntityTransaction - 我有一个例外java.sql.SQLException: Error in allocating a connection. Cause: In-use connections equal max-pool-size and expired max-wait-time. Cannot allocate more connections.
我做错了什么? 此代码在tomcat上运行正常 堆栈跟踪是:

Exception Description: Cannot use an EntityTransaction while using JTA.
    at org.eclipse.persistence.internal.jpa.transaction.JTATransactionWrapper.getTransaction(JTATransactionWrapper.java:65)
    at org.eclipse.persistence.internal.jpa.EntityManagerImpl.getTransaction(EntityManagerImpl.java:1103)
    at com.eximb.fpcm.server.eclipselink.jpa.ParametrizedEntityManager.getTransaction(ParametrizedEntityManager.java:314)
    at com.eximb.fpcm.server.service.api.AbstractCommand.invoke(AbstractCommand.java:52)
    at com.eximb.fpcm.server.service.orgUnit.OrgUnitServiceImpl.findAll(OrgUnitServiceImpl.java:39)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:569)
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208)
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
    at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
    at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:332)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:233)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
    at java.lang.Thread.run(Thread.java:619)

1 个答案:

答案 0 :(得分:0)

看起来你没有使用JTA。但是,您的persistence.xml配置为执行此操作。尝试更改此行:

<persistence-unit name="fpkmPU" transaction-type="JTA">

到此:

<persistence-unit name="fpkmPU" transaction-type="RESOURCE_LOCAL">