Code example for SessionFactory

Methods: openSession

0
		} 
 
		@Override 
		public void run() { 
			try { 
				Session s = sf.openSession();
				Transaction tx = s.beginTransaction();
				Worker w = new Worker( "Mladen", 70 );
				s.persist( w );
				Construction c = new Construction( "Hover Dam", "Croatia" );
				s.persist( c );
				tx.commit();
				s.close();
 
				s = sf.openSession();
				tx = s.beginTransaction();
				w = (Worker) s.get( Worker.class, w.getId() );
				w.setName( "Remi" );
				c = (Construction) s.get( Construction.class, c.getId() );
				c.setName( "Palais des festivals" );
				tx.commit();
				s.close();
 
				s = sf.openSession();
				tx = s.beginTransaction();
				w = (Worker) s.get( Worker.class, w.getId() );
				s.delete( w );
				c = (Construction) s.get( Construction.class, c.getId() );
				s.delete( c );