Skip to content

Instantly share code, notes, and snippets.

@rvazquezglez
Created December 1, 2012 11:36
Show Gist options
  • Save rvazquezglez/4181651 to your computer and use it in GitHub Desktop.
Save rvazquezglez/4181651 to your computer and use it in GitHub Desktop.
Clase DAO para Banco.
public class BancoDAO {
public int insertar(Banco banco) {
Session session = HibernateUtil.getSessionFactory().openSession();
// Inicia una transaccion
Transaction transaccion = session.beginTransaction();
int idBanco = -1;
try {
idBanco = (Integer) session.save(banco); // INSERT INTO BANCO .....
transaccion.commit();
} catch (HibernateException he) {
he.printStackTrace();
transaccion.rollback();
} finally {
session.close();
}
return idBanco;
}
// Obtener por id
// Banco banco = (Banco) session.get(Banco.class, idBanco);
// Delete
// session.delete(banco);
// Update
// session.update(bancoEncontrado);
// List
// List<Banco> bancos = session.createQuery("from Banco").list();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment