Skip to content

Instantly share code, notes, and snippets.

@ajfmo
Created February 16, 2018 13:31
Show Gist options
  • Save ajfmo/ead82710b05755131668b48d49a2bfde to your computer and use it in GitHub Desktop.
Save ajfmo/ead82710b05755131668b48d49a2bfde to your computer and use it in GitHub Desktop.
import java.util.List;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import org.hibernate.Session;
import org.hibernate.Transaction;
import ajfmo.inventario.entities.Deposito;
import ajfmo.inventario.utils.HibernateUtil;
public class DepositoDAO {
// Hibernate
private Session session = HibernateUtil.getSessionFactory();
private Transaction tx = null;
private CriteriaBuilder builder = session.getCriteriaBuilder();
// Objects
private Deposito deposit;
/*******************/
/** **/
/*** Source Code ***/
/** **/
/*******************/
/**
* @param descripcionDeposito
*/
public void createDeposit(String descripcionDeposito) {
deposit = new Deposito(descripcionDeposito);
tx = session.beginTransaction();
session.save(deposit);
tx.commit();
}
/**
* @return
*/
public List<Deposito> depositCriteria() {
CriteriaQuery<Deposito> criteria = builder.createQuery(Deposito.class);
Root<Deposito> root = criteria.from(Deposito.class);
criteria.select(root);
List<Deposito> resultset = session.createQuery(criteria).getResultList();
return resultset;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment