Code example for Session

Methods: closeloadbeginTransaction

0
	 * <p/> 
	 * one hibernate transaction 
	 */ 
	private void addObject2() throws HibernateException {
		Session session = openSession();
		Transaction tx = session.beginTransaction();
 
		MainObject mo =
				( MainObject ) session.load( MainObject.class, generatedId );
 
		Object2 toAdd = new Object2();
		toAdd.setDummy( "test" );
 
		//toAdd should now be saved by cascade 
		mo.setObj2( toAdd );
 
		tx.commit();
		session.close();
	} 
 
	/** 
	 * reads the newly created MainObject 
	 * and its Object2 if it exists 
Connect your IDE to all the code out there  Get Codota for Java