Example usage for org.hibernate.resource.transaction.spi TransactionStatus isNotOneOf

List of usage examples for org.hibernate.resource.transaction.spi TransactionStatus isNotOneOf

Introduction

In this page you can find the example usage for org.hibernate.resource.transaction.spi TransactionStatus isNotOneOf.

Prototype

public boolean isNotOneOf(TransactionStatus... statuses) 

Source Link

Usage

From source file:org.jboss.additional.testsuite.jdkall.past.jpa.hibernate.secondlevelcache.SFSB.java

License:Open Source License

public Student createStudent(String firstName, String lastName, String address, int id) {
    // setupConfig();
    Student student = new Student();
    student.setStudentId(id);//from   w  w w.j  a va 2s.c  om
    student.setAddress(address);
    student.setFirstName(firstName);
    student.setLastName(lastName);

    try {
        Session session = sessionFactory.openSession();
        Transaction ormTransaction = session.beginTransaction(); // join the current JTA transaction
        TransactionStatus status = ormTransaction.getStatus();
        if (status.isNotOneOf(TransactionStatus.ACTIVE)) {
            throw new RuntimeException(
                    "Hibernate Transaction is not active after joining Hibernate to JTA transaction: "
                            + status.name());
        }
        session.save(student);
        // trans.commit();
        session.close();
    } catch (Exception e) {

        e.printStackTrace();
        throw new RuntimeException("Failure while persisting student entity", e);

    }
    return student;
}

From source file:org.jboss.additional.testsuite.jdkall.past.jpa.hibernate.secondlevelcache.SFSB.java

License:Open Source License

public Student getStudent(int id) {
    Student student;//ww w .  j  a v a  2s  .  co m

    try {
        Session session = sessionFactory.openSession();
        Transaction ormTransaction = session.beginTransaction(); // join the current JTA transaction
        TransactionStatus status = ormTransaction.getStatus();
        if (status.isNotOneOf(TransactionStatus.ACTIVE)) {
            throw new RuntimeException(
                    "Hibernate Transaction is not active after joining Hibernate to JTA transaction: "
                            + status.name());
        }
        student = session.load(Student.class, id);
        session.close();

    } catch (Exception e) {

        e.printStackTrace();
        throw new RuntimeException("Failure while loading student entity", e);

    }
    return student;
}