Code example for Session

Methods: clearcloseflushgetpersistbeginTransaction

0
 */ 
public class QuoteGlobalTest extends BaseCoreFunctionalTestCase { 
	@Test
	public void testQuoteManytoMany() { 
		Session s = openSession();
		Transaction tx = s.beginTransaction();
		User u = new User();
		s.persist( u );
		Role r = new Role();
		s.persist( r );
		u.getRoles().add( r );
		s.flush();
		s.clear();
		u = (User) s.get( User.class, u.getId() );
		assertEquals( 1, u.getRoles().size() );
		tx.rollback();
		String role = User.class.getName() + ".roles";
		assertEquals( "User_Role", configuration().getCollectionMapping( role ).getCollectionTable().getName() );
		s.close();
	} 
 
	@Override 
	protected void configure(Configuration cfg) {
		super.configure( cfg );