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:bean.RegisterBean.java

public void register() {
    Matcher matcherEm = EMAIL_REGEX.matcher(eMail);
    Matcher matcherPass = PASSWORD_REGEX.matcher(password);
    boolean errorHappened = false;
    if (!password.equals(passwordConfirmation)) {
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,
                "Error:", "Password and password confirmation do not match!"));
        errorHappened = true;/*from  ww  w .j  ava2s .  c om*/
    }
    if (!matcherEm.find()) {
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,
                "Error:", "The email address isn't in the right format!"));
        errorHappened = true;
    }
    if (!matcherPass.find()) {
        FacesContext.getCurrentInstance().addMessage(null,
                new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error:", "Password isn't in the right format!"));
        errorHappened = true;
    }
    if (!errorHappened) {
        try {
            Session session = HibernateUtil.getSessionFactory().openSession();
            Transaction transaction = session.beginTransaction();
            User usr = new User();
            usr.setEMail(eMail);
            usr.setFirstName(firstName);
            usr.setLastName(lastName);
            usr.setPassword(password);
            usr.setPhone(phone);
            usr.setStatus("pending");
            usr.setUsername(username);
            session.persist(usr);
            transaction.commit();
            FacesContext.getCurrentInstance().getExternalContext().redirect("index.xhtml");
            FacesContext.getCurrentInstance().responseComplete();
        } catch (ConstraintViolationException e) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,
                    "Error:", "This username or email is already taken!"));
        } catch (IOException e) {
            FacesContext.getCurrentInstance().addMessage(null,
                    new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error:", "Something bad happened!"));
        }
    }
}

From source file:br.com.itw.qopsearch.api.persistence.core.FeatureProductRepositoryImpl.java

License:Apache License

@Override
public ProductFeature create(ProductFeature productFeature) {
    Session session = (Session) entityManager.getDelegate();
    session.persist(productFeature);
    return productFeature;
}

From source file:br.com.itw.qopsearch.api.persistence.core.FeatureRepositoryImpl.java

License:Apache License

@Override
public Feature create(Feature feature) {
    Session session = (Session) entityManager.getDelegate();
    session.persist(feature);
    return feature;
}

From source file:br.com.itw.qopsearch.api.persistence.core.ProductRepositoryImpl.java

License:Apache License

@Override
public Product create(Product product) {
    Session session = (Session) entityManager.getDelegate();
    session.persist(product);
    return product;
}

From source file:br.edu.ifsp.dsw.dao.impl.TagDAOImpl.java

@Override
public void incluirTag(Tag t) {
    Session session = this.sessionFactory.getCurrentSession();
    session.persist(t);
    logger.info("Tag includa com sucesso, detalhes da tag=" + t);
}

From source file:br.edu.ifsp.dsw.dao.impl.UsuarioDAOImpl.java

@Override
public void incluirUsuario(Usuario u) {
    // TODO Auto-generated method stub
    Session session = this.sessionFactory.getCurrentSession();
    session.persist(u);
    logger.info("Usuario includo com sucesso, detalhes =" + u);
}

From source file:br.sp.telesul.dao.FuncionarioDAOImpl.java

@Override
public void save(Funcionario funcionario) {
    Session session = this.sessionFactory.openSession();

    try {//from  w ww  .  j  a  va  2  s . c  o m
        tx = session.beginTransaction();
        session.persist(funcionario);
        tx.commit();

        logger.info("Save Sucessfully funcionrio", funcionario.getNome());
    } catch (Exception e) {
        if (tx != null) {
            tx.rollback();
        }
        logger.error("Error in save funcionrio", e);
        System.out.println("erro" + e);
    } finally {
        session.close();
    }

}

From source file:br.uece.goes.model.ObjectDAO.java

public void save(Object p) {

    Session s = openSession();
    s.beginTransaction();
    s.persist(p);
    s.getTransaction().commit();
    s.close();
}

From source file:br.ufmt.ic.paw2.DAO.PacienteDAO.java

public void gravar(final Paciente paciente) {

    Paciente merge;// www . java 2s .c  om

    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction t = session.beginTransaction();

    if ((paciente != null) && (paciente.getId() > 0)) {
        merge = (Paciente) session.merge(paciente);
        session.persist(merge);
    }

    else
        session.persist(paciente);

    t.commit();

}

From source file:br.univel.common.Dao.java

public void create(Model model) {

    Session session = HibernateUtil.getSessionFactory().openSession();
    session.beginTransaction();/*from w  ww  .  ja  va2s . c  o  m*/
    session.persist(model);
    session.getTransaction().commit();
    session.close();
    //    HibernateUtil.finalizar();
}