Example usage for org.hibernate Transaction markRollbackOnly

List of usage examples for org.hibernate Transaction markRollbackOnly

Introduction

In this page you can find the example usage for org.hibernate Transaction markRollbackOnly.

Prototype

default void markRollbackOnly() 

Source Link

Document

Make a best effort to mark the underlying transaction for rollback only.

Usage

From source file:org.glite.security.voms.admin.integration.orgdb.database.OrgDBSessionFactory.java

License:Apache License

public static void commitTransaction() {
    if (orgDbSessionFactory == null)
        throw new OrgDBError("Session factory not initialized!");

    Session s = orgDbSessionFactory.getSessionFactory().getCurrentSession();

    if (!s.isConnected()) {
        throw new OrgDBError("Session to OrgDB is not connected");
    }//from  w  ww  .ja  v a 2 s  . c  om

    Transaction tx = s.getTransaction();

    if (tx == null) {
        throw new OrgDBError("Cannot commit a null transaction");
    }

    if (!tx.isActive()) {
        throw new OrgDBError("Cannot commit an inactive transaction");
    }

    try {
        tx.commit();
    } catch (RollbackException e) {
        log.error("Error committing OrgDB transaction: " + e.getMessage(), e);
        tx.markRollbackOnly();
        rollbackTransaction();
    }

}