KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > test > orphan > PropertyRefTest


1 // $Id: PropertyRefTest.java,v 1.2 2005/06/22 18:58:16 oneovthafew Exp $
2
package org.hibernate.test.orphan;
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
12 /**
13  * Test for HHH-565
14  *
15  * @author Steve Ebersole
16  */

17 public class PropertyRefTest extends TestCase {
18
19     public PropertyRefTest(String JavaDoc name) {
20         super( name );
21     }
22
23     protected String JavaDoc[] getMappings() {
24         return new String JavaDoc[] {
25             "orphan/User.hbm.xml",
26             "orphan/Mail.hbm.xml"
27         };
28     }
29
30     public void testDeleteParentWithBidirOrphanDeleteCollectionBasedOnPropertyRef() {
31         Session session = openSession();
32         Transaction txn = session.beginTransaction();
33         User user = new User( "test" );
34         user.addMail( "test" );
35         user.addMail( "test" );
36         session.save( user );
37         txn.commit();
38         session.close();
39
40         session = openSession();
41         txn = session.beginTransaction();
42         user = ( User ) session.load( User.class, user.getId() );
43         session.delete( user );
44         txn.commit();
45         session.close();
46
47         session = openSession();
48         txn = session.beginTransaction();
49         session.createQuery( "delete from Mail where alias = :alias" ).setString( "alias", "test" ).executeUpdate();
50         session.createQuery( "delete from User where userid = :userid" ).setString( "userid", "test" ).executeUpdate();
51         txn.commit();
52         session.close();
53     }
54
55     public static Test suite() {
56         return new TestSuite(PropertyRefTest.class);
57     }
58     
59 }
60
Popular Tags