//$Id: QuoteTest.java 19399 2010-05-07 07:18:16Z stliu $
package org.hibernate.test.annotations.quote;

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.test.annotations.TestCase;

/**
 * @author Emmanuel Bernard
 */
public class QuoteTest extends TestCase {
	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", getCfg().getCollectionMapping( role ).getCollectionTable().getName() );
		s.close();
	}
	protected Class[] getAnnotatedClasses() {
		return new Class[] {
				User.class,
				Role.class
		};
	}
}
