Search code examples
javajpatransactionsopenjpaopenejb

javax.ejb.EJBTransactionRolledbackException - get stacktrace for origin


In my web application I use OpenJPA. Sometimes when I make database operation I get this exception:

javax.servlet.ServletException: javax.el.ELException: javax.ejb.EJBTransactionRolledbackException: Transaction was rolled back, presumably because setRollbackOnly was called during a synchronization

with root case:

org.apache.geronimo.transaction.manager.SetRollbackOnlyException: setRollbackOnly() called.  See stacktrace for origin

The question is: how to get stacktrace for exception which was thrown in transaction?

I look here

but I don't understand it.

I think I get this exception every time when I try to save big file (more than 2MB) to the table at database.


Solution

  • I recommend to set this properties inside your persistece.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="laudoweb_pu">
            <jta-data-source>jdbc/integracaolaudoweb</jta-data-source>
            <class>com.xxx.xxxEntity</class>
            <properties>
                <property name="openjpa.jdbc.DBDictionary" value="oracle" />
                <property name="openjpa.Log" value="DefaultLevel=WARN, Runtime=INFO, Tool=INFO, SQL=TRACE"/>
                <property name="openjpa.AutoDetach" value="close" />
                <property name="openjpa.DetachState" value="loaded" />
                <property name="openjpa.DataCache" value="false" />
                <property name="openjpa.Optimistic" value="true" />
                <property name="openjpa.Multithreaded" value="true" />
                <property name="openjpa.TransactionMode" value="managed" />
                <property name="openjpa.ConnectionFactoryMode" value="managed" />
                <property name="openjpa.NontransactionalRead" value="true" />
                <property name="openjpa.RestoreState" value="all" />
                <property name="openjpa.ManagedRuntime" value="auto" />
            </properties>
        </persistence-unit>
    </persistence>
    

    Here the openjpa documentation for logs and other properties.

    http://openjpa.apache.org/builds/1.0.2/apache-openjpa-1.0.2/docs/manual/ref_guide_logging_openjpa.html

    Mainly this line is important for log and trace:

     <property name="openjpa.Log" value="DefaultLevel=WARN, Runtime=INFO, Tool=INFO, SQL=TRACE"/>