1

Glassfish 3.1.2 + JPA + EclipseLink + MySQL を使用して開発されたアプリケーションで問題が発生しました。アプリケーションをデプロイした直後 (DB にテーブルはありません) は正常に動作し、明らかに唯一のクエリを実行します (テーブル内のエンティティをカウントします)。私が入ったこと。しかし、ページをリロードすると、サーブレットを再度呼び出すと例外がスローされます: TransactionRolledbackLocalException

どうやら、エンティティをカウントするために使用されるのと同じ方法で。

次に、もう一度リロードすると、正常に実行され、再び例外、正常、例外など...

これは私のサーブレットです:

@WebServlet(name="Controller", urlPatterns={"/Controller"})
public class Controller extends HttpServlet {
    private static final long serialVersionUID = 1L;

    @EJB WineDao _wines;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        _wines.countWines();

        RequestDispatcher view = request.getRequestDispatcher("ShowAll.jsp");
        view.forward(request, response);
    }
} 

これはワインダオです:

@Stateless
public class WineDao {
    @PersistenceContext private EntityManager em;

    public Long countWines() {
        CriteriaBuilder qb = em.getCriteriaBuilder();
        CriteriaQuery<Long> cq = qb.createQuery(Long.class);
        cq.select(qb.count(cq.from(Wine.class)));
        return em.createQuery(cq).getSingleResult();
    }

}

persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
    <persistence version="2.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_2_0.xsd">
    <persistence-unit name="myPU" transaction-type="JTA">
        <jta-data-source>jdbc/MySQLDataSource</jta-data-source>
        <properties>
            <!-- drop and create tables at deployment -->
            <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
            <!-- log sqls executed in server.log -->
            <property name="eclipselink.logging.level" value="FINE"/>
            <!-- Instruct EclipseLink to not log execeptions it throws. Lets the application decide about it-->
            <property name="eclipselink.logging.exceptions" value="true"/>
        </properties>
    </persistence-unit>
</persistence>

そして最後に、エラーが発生しない場合のサーバーログ:

[#|2013-01-07T18:32:27.271+0100|FINE|glassfish3.1.2|org.eclipse.persistence.session.file:/opt/glassfish/glassfish/domains/domain1/applications/appname/WEB-INF/classes/_myPU.sql|_ThreadID=21;_ThreadName=Thread-2;ClassName=null;MethodName=null;|SELECT COUNT(ID) FROM Wine|#]

そして、エラーが発生したとき:

[#|2013-01-07T18:32:29.582+0100|WARNING|glassfish3.1.2|javax.enterprise.system.container.ejb.com.sun.ejb.containers|_ThreadID=20;_ThreadName=Thread-2;|EJB5184:A system exception occurred during an invocation on EJB WineDao, method: public java.lang.Long it.vitux.java.appname.dao.WineDao.countWines()|#]

[#|2013-01-07T18:32:29.583+0100|WARNING|glassfish3.1.2|javax.enterprise.system.container.ejb.com.sun.ejb.containers|_ThreadID=20;_ThreadName=Thread-2;|javax.ejb.TransactionRolledbackLocalException: Client's transaction aborted
    at com.sun.ejb.containers.BaseContainer.useClientTx(BaseContainer.java:4722)
    at com.sun.ejb.containers.BaseContainer.preInvokeTx(BaseContainer.java:4601)
    at com.sun.ejb.containers.BaseContainer.preInvoke(BaseContainer.java:1914)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:212)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
    at $Proxy516.countWines(Unknown Source)
    at it.vitux.java.appname.dao.__EJB31_Generated__WineDao__Intf____Bean__.countWines(Unknown Source)
    at it.vitux.java.appname.controllers.Controller.doGet(Controller.java:43)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
    at com.sun.grizzly.http.ajp.AjpProcessorTask.invokeAdapter(AjpProcessorTask.java:125)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:679)
|#]

[#|2013-01-07T18:32:29.591+0100|WARNING|glassfish3.1.2|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=20;_ThreadName=Thread-2;|StandardWrapperValve[Controller]: PWC1406: Servlet.service() for servlet Controller threw exception
javax.ejb.EJBTransactionRolledbackException
    at com.sun.ejb.containers.BaseContainer.mapLocal3xException(BaseContainer.java:2314)
    at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2096)
    at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1994)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:222)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
    at $Proxy516.countWines(Unknown Source)
    at it.vitux.java.appname.dao.__EJB31_Generated__WineDao__Intf____Bean__.countWines(Unknown Source)
    at it.vitux.java.appname.controllers.Controller.doGet(Controller.java:43)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
    at com.sun.grizzly.http.ajp.AjpProcessorTask.invokeAdapter(AjpProcessorTask.java:125)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:679)
Caused by: javax.ejb.TransactionRolledbackLocalException: Client's transaction aborted
    at com.sun.ejb.containers.BaseContainer.useClientTx(BaseContainer.java:4722)
    at com.sun.ejb.containers.BaseContainer.preInvokeTx(BaseContainer.java:4601)
    at com.sun.ejb.containers.BaseContainer.preInvoke(BaseContainer.java:1914)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:212)
    ... 31 more
|#]

Wineクラスを忘れました:

@Entity
public class Wine {
    public static final int UP_ADDED = 0;
    public static final int UP_REMOVED = 1;
    public static final int UP_PRICE = 2;
    public static final int UP_OFFER = 3;

    @Id Long id; 
    private String name;
    private BigDecimal price;
    private BigDecimal offer;
    @Temporal(TemporalType.TIMESTAMP)
    private Date updateTime;
    private int updateStatus = 0;

    // Getters + Setters
}
4

1 に答える 1

5

私は最終的に解決策を見つけました.glassfishドメインを再起動します-.-1日の試行の後、それは奇妙です。

于 2013-01-08T14:33:43.840 に答える