Diferencia entre revisiones de «Usuario:Lmorillas/desarrollo web servidor/jee/intro hibernate»
De WikiEducator
(→BuildSessionFactory) |
|||
Línea 23: | Línea 23: | ||
== Más docs.== | == Más docs.== | ||
* http://docs.jboss.org/hibernate/orm/4.1/quickstart/en-US/html_single/ | * http://docs.jboss.org/hibernate/orm/4.1/quickstart/en-US/html_single/ | ||
+ | * http://www.cursohibernate.es/doku.php | ||
}} | }} | ||
}} | }} |
Revisión de 01:54 1 feb 2013
Objetivos
Tareas
Guión
Tip:
Más docs.
|
BuildSessionFactory
import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistryBuilder; // private static SessionFactory sessionFactory; private static ServiceRegistry serviceRegistry; Session session = null; try { try { Configuration cfg = new Configuration().addResource( "configuracion_file.hbm.xml").configure(); serviceRegistry = new ServiceRegistryBuilder().applySettings( cfg.getProperties()).buildServiceRegistry(); sessionFactory = cfg.buildSessionFactory(serviceRegistry); } catch (Throwable ex) { System.err.println("Failed to create sessionFactory object."+ ex); throw new ExceptionInInitializerError(ex); } session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); // session.save(xxx); tx.commit(); } catch (Exception e) { System.out.println(e.getMessage()); } finally { session.close(); }