Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package poo.estacionamiento.controller; import org.hibernate.SessionFactory; import org.hibernate.boot.MetadataSources; import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import poo.estacionamiento.Usuario; import poo.estacionamiento.dao.AbonosPropietarioDao; import poo.estacionamiento.dao.AbonosPropietarioDaoHibernateImpl; import poo.estacionamiento.dao.PropietariosDao; import poo.estacionamiento.dao.PropietariosDaoHibernateImpl; import poo.estacionamiento.dao.UsuariosDao; import poo.estacionamiento.dao.UsuariosDaoHibernateImpl; /** * * @author joaquinleonelrobles */ public class Main { public static void main(String[] args) { SessionFactory sessionFactory = null; // A SessionFactory is set up once for an application! final StandardServiceRegistry registry = new StandardServiceRegistryBuilder() .configure("resources/hibernate.cfg.xml") // configures settings from hibernate.cfg.xml .build(); try { sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory(); } catch (Exception e) { // The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory // so destroy it manually. StandardServiceRegistryBuilder.destroy(registry); throw e; } PropietariosDao propietariosDao = new PropietariosDaoHibernateImpl(sessionFactory); AbonosPropietarioDao abonosPropietarioDao = new AbonosPropietarioDaoHibernateImpl(sessionFactory); UsuariosDao usuariosDao = new UsuariosDaoHibernateImpl(sessionFactory); // obtenemos el usuario logueado Usuario polo = usuariosDao.buscarPorNombre("polo"); new GestorCobroAbono(propietariosDao, abonosPropietarioDao, polo).run(); } }