1 package org.hibernate.test.mapelemformula; 3 4 import junit.framework.Test; 5 import junit.framework.TestSuite; 6 7 import org.hibernate.Session; 8 import org.hibernate.Transaction; 9 import org.hibernate.test.TestCase; 10 11 14 public class MapElementFormulaTest extends TestCase { 15 16 public MapElementFormulaTest(String str) { 17 super(str); 18 } 19 20 public void testManyToManyFormula() { 21 Session s = openSession(); 22 Transaction t = s.beginTransaction(); 23 User gavin = new User("gavin", "secret"); 24 User turin = new User("turin", "tiger"); 25 Group g = new Group("users"); 26 g.getUsers().put("Gavin", gavin); 27 g.getUsers().put("Turin", turin); 28 s.persist(g); 29 t.commit(); 30 s.close(); 31 32 s = openSession(); 33 t = s.beginTransaction(); 34 g = (Group) s.get(Group.class, "users"); 35 assertEquals( g.getUsers().size(), 2 ); 36 g.getUsers().remove("Turin"); 37 t.commit(); 38 s.close(); 39 40 s = openSession(); 41 t = s.beginTransaction(); 42 g = (Group) s.get(Group.class, "users"); 43 assertEquals( g.getUsers().size(), 1 ); 44 s.delete(g); 45 s.delete( g.getUsers().get("Gavin") ); 46 s.delete( s.get(User.class, "turin") ); 47 t.commit(); 48 s.close(); 49 } 50 51 protected String [] getMappings() { 52 return new String [] { "mapelemformula/UserGroup.hbm.xml" }; 53 } 54 55 public static Test suite() { 56 return new TestSuite(MapElementFormulaTest.class); 57 } 58 59 } 60 61 | Popular Tags |