Example usage for org.hibernate Session persist

List of usage examples for org.hibernate Session persist

Introduction

In this page you can find the example usage for org.hibernate Session persist.

Prototype

void persist(Object object);

Source Link

Document

Make a transient instance persistent.

Usage

From source file:com.dalamar.model.StatSnapshotDaoImpl.java

@Override
public void save(StatSnapshot snp) {
    Session session = this.sessionFactory.openSession();
    Transaction tx = session.beginTransaction();
    session.persist(snp);
    tx.commit();//  w  ww .  ja v a  2  s.  co m
    session.close();
}

From source file:com.Dao.UsuarioDao.java

public void guardarUser(Usuario us) {
    Session sess = factory.openSession();
    try {/*w  ww . ja va2  s  . com*/
        sess.beginTransaction();
        sess.persist(us);
        sess.getTransaction().commit();
    } catch (Exception e) {
        if (sess.getTransaction() != null) {
            sess.getTransaction().rollback();
        }
        e.printStackTrace();
    } finally {
        sess.close();
    }
}

From source file:com.daro.persistence.generic.dao.GenericDaoImpl.java

License:GNU General Public License

/**
 * Persist new entity p./*from  w  w w. j  av a 2 s  . c om*/
 * 
 * @param p Data type of entity.
 * @throws PersistenceException
 */
@Override
public void add(T p) throws PersistenceException {

    Session session = this.getCurrentSession();

    try {
        session.persist(p);
    } catch (java.lang.IllegalArgumentException illegalArgumentEx) {
        logger.error("Persistence layer error: " + illegalArgumentEx.getStackTrace());
        PersistenceError error;
        if (p == null) {
            error = PersistenceError.ENTITY_NULL;
        } else {
            error = PersistenceError.PERSISTENCE_INTERNAL_ERROR;
        }
        throw new PersistenceException(error, illegalArgumentEx.getCause());
    }

    if (loggerInfoEnabled)
        logger.debug("Persistence layer info: " + "Saved successfully, Details=" + p);
}

From source file:com.dgc.DAO.GenericDao.java

public E persist(E entity) {

    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/* w  w  w  . ja v a2  s  .  c  o m*/
    session.persist(entity);
    session.getTransaction().commit();
    return entity;

}

From source file:com.digitalizat.organization.dao.OrganizationDaoIml.java

@Override
public void addOrganization(Organization org) {
    Session session = sessionFactory.getCurrentSession();
    session.persist(org);
}

From source file:com.digitalizat.user.dao.UserDAOImpl.java

@Override
public void addUser(User user) {
    Session session = sessionFactory.getCurrentSession();
    session.persist(user);
}

From source file:com.dragansah.demoapp.services.AppModule.java

License:Apache License

@Startup
public void fillDB(Session session) {
    Transaction t = session.beginTransaction();
    Department deptAcc = new Department("acc", "Accounting");
    Department deptTV = new Department("tv", "Television");
    Department deptMgmt = new Department("mgmt", "Management");

    session.persist(deptAcc);
    session.persist(deptTV);//  w ww .j  ava2 s. co  m
    session.persist(deptMgmt);

    session.persist(new Employee("Jack", "Donaghy", 500, deptMgmt));
    session.persist(new Employee("Liz", "Lemon", 400, deptAcc));
    session.persist(new Employee("Tracy", "Jordan", 700, deptTV));
    t.commit();
}

From source file:com.ecama.dao.ContestDAOImpl.java

@Override
public void addContents(Contents c) {
    Session session = this.sessionFactory.getCurrentSession();
    session.persist(c);
}

From source file:com.ecama.dao.ImagesDAOImpl.java

@Override
public void addImage(Images img) {
    Session session = this.sessionFactory.getCurrentSession();
    session.persist(img);

}

From source file:com.ecama.dao.UserDAOImpl.java

@Override
public void addUser(User u) {
    Session session = this.sessionFactory.getCurrentSession();
    session.persist(u);
    logger.info("User saved successfully, User Details=" + u);
}