Example usage for org.hibernate Transaction setTimeout

List of usage examples for org.hibernate Transaction setTimeout

Introduction

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

Prototype

void setTimeout(int seconds);

Source Link

Document

Set the transaction timeout for any transaction started by a subsequent call to #begin on this instance.

Usage

From source file:dao.FacultyDAO.java

@Override
public void updateFaculty(Faculty faculty) {
    Session sess = sessionFactory.openSession();
    Transaction tx = sess.getTransaction();
    try {/*from   w w w.j a v a2s  .com*/
        //set transaction timeout to 3 seconds
        tx.setTimeout(3);
        tx.begin();
        Faculty c = (Faculty) sess.get(Faculty.class,faculty.getIdFaculty());
        c.setFirstName(faculty.getFirstName());
        c.setLastName(faculty.getLastName());
        c.setMiddleName(faculty.getMiddleName());
        c.setUserName(faculty.getUserName());
        c.setPassword(faculty.getPassword());
        c.setGender(faculty.getGender());
        tx.commit();
    } catch (Exception e) {
        tx.rollback();
        throw e; // or display error message
    } finally {
        sess.close();
    }
        
}

From source file:dao.FacultyDAO.java

@Override
public void deleteFaculty(Integer idFaculty) {
    Session sess = sessionFactory.openSession();
    Transaction tx = sess.getTransaction();
    try {/*from  www  .  j a va  2 s . co  m*/
        //set transaction timeout to 3 seconds
        tx.setTimeout(3);
        tx.begin();
        Faculty c = (Faculty) sess.get(Faculty.class,idFaculty);
        sess.delete(c);
        tx.commit();
    } catch (Exception e) {
        tx.rollback();
        throw e; // or display error message
    } finally {
        sess.close();
    }
}

From source file:dao.FacultyDAO.java

@Override
public List<Faculty> getAllFaculties(){
    List<Faculty> obj;/*w  w  w .jav a2 s  .com*/
    Session sess = sessionFactory.openSession();
    Transaction tx = sess.getTransaction();
    try {
        //set transaction timeout to 3 seconds
        tx.setTimeout(3);
        tx.begin();
            
        Query queryResult = sess.createQuery("from Faculty"); 
        obj = queryResult.list();
        tx.commit();
    } catch (Exception e) {
        tx.rollback();
        throw e; // or display error message
    } finally {
        sess.close();
    }
    return obj;
}

From source file:dao.ProductCategoryDAO.java

@Override
public void addProductCategory(ProductCategory productCategory) {
    Session sess = sessionFactory.openSession();
    Transaction tx = sess.getTransaction();
    try {/*ww w .j ava 2 s  . c om*/
        //set transaction timeout to 3 seconds
        tx.setTimeout(3);
        tx.begin();

        sess.save(productCategory);

        sess.getTransaction().commit();
    } catch (Exception e) {
        tx.rollback();
        throw e; // or display error message
    } finally {
        sess.close();
    }

}

From source file:dao.ProductCategoryDAO.java

@Override
public void updateProductCategory(ProductCategory productCategory) {
    Session sess = sessionFactory.openSession();
    Transaction tx = sess.getTransaction();
    try {/*from   w  ww . j av  a2s.c  o  m*/
        //set transaction timeout to 3 seconds
        tx.setTimeout(3);
        tx.begin();

        //            System.out.println("Hello " + productCategory.getIdProductCategory());

        ProductCategory c = (ProductCategory) sess.get(ProductCategory.class,
                productCategory.getIdProductCategory());
        c.setDescription(productCategory.getDescription());
        c.setName(productCategory.getName());
        c.setParentCategory(productCategory.getParentCategory());

        sess.getTransaction().commit();
    } catch (Exception e) {
        tx.rollback();
        throw e; // or display error message
    } finally {
        sess.close();
    }

}

From source file:dao.ProductCategoryDAO.java

@Override
public void deleteProductCategory(Integer IdProductCategory) {
    Session sess = sessionFactory.openSession();
    Transaction tx = sess.getTransaction();
    try {/*from ww  w . ja v a  2  s .com*/
        //set transaction timeout to 3 seconds
        tx.setTimeout(3);
        tx.begin();
        ProductCategory c = (ProductCategory) sess.get(ProductCategory.class, IdProductCategory);
        sess.delete(c);

        tx.commit();
    } catch (Exception e) {
        tx.rollback();
        throw e; // or display error message
    } finally {
        sess.close();
    }

}

From source file:dao.ProductCategoryDAO.java

@Override
public ProductCategory getProductCategory(Integer IdProductCategory) {
    ProductCategory cs;/*from  w  w w .  j av  a2 s.  c om*/
    Session sess = sessionFactory.openSession();
    Transaction tx = sess.getTransaction();
    try {
        //set transaction timeout to 3 seconds
        tx.setTimeout(3);
        tx.begin();
        cs = (ProductCategory) sess.get(ProductCategory.class, IdProductCategory);

        tx.commit();
    } catch (Exception e) {
        tx.rollback();
        throw e; // or display error message
    } finally {
        sess.close();
    }

    return cs;
}

From source file:dao.ProductCategoryDAO.java

@Override
public List findAll() {
    List<ProductCategory> cs;
    Session sess = sessionFactory.openSession();
    Transaction tx = sess.getTransaction();
    try {//  www .  ja  v  a2  s . c om
        //set transaction timeout to 3 seconds

        tx.setTimeout(3);
        tx.begin();
        Query queryResult = sess.createQuery("from ProductCategory");
        cs = queryResult.list();

        tx.commit();
    } catch (Exception e) {
        tx.rollback();
        throw e; // or display error message
    } finally {
        sess.close();
    }
    return cs;
}

From source file:de.micromata.genome.jpa.EmgrTx.java

License:Apache License

private void setTransactionTimeOut(E emgr) {
    if (timeout == -1) {
        return;/*  w w w. j av  a  2  s . c  o m*/
    }
    Session session = emgr.getEntityManager().unwrap(Session.class);
    Transaction trans = session.getTransaction();
    trans.setTimeout((int) (timeout / 1000));

}

From source file:edu.nps.moves.mmowgli.hibernate.SearchManager.java

License:Open Source License

private static Pkt _preAmble() {
    Session sess = VHib.getSessionFactory().openSession();
    FullTextSession srSess = Search.getFullTextSession(sess);
    Transaction srTx = srSess.beginTransaction();
    srTx.setTimeout(HIBERNATE_TRANSACTION_TIMEOUT_IN_SECONDS);
    return new Pkt(sess, srSess, srTx);
}