1 | Contract c = new Contract("gavin", "phone");↵ | | 1 | Contract c = new Contract("gavin", "phone");↵
|
2 | ContractVariation cv1 = new ContractVariation(1, c);↵ | | 2 | ContractVariation cv1 = new ContractVariation(1, c);↵
|
3 | cv1.setText("expensive");↵ | | 3 | cv1.setText("expensive");↵
|
4 | ContractVariation cv2 = new ContractVariation(2, c);↵ | | 4 | ContractVariation cv2 = new ContractVariation(2, c);↵
|
5 | cv2.setText("more expensive");↵ | | 5 | cv2.setText("more expensive");↵
|
6 | Session s = openSession();↵ | | 6 | Session s = openSession();↵
|
7 | Transaction t = s.beginTransaction();↵ | | 7 | Transaction t = s.beginTransaction();↵
|
8 | s.persist(c);↵ | | 8 | s.persist(c);↵
|
9 | t.commit();↵ | | 9 | t.commit();↵
|
10 | s.close();↵ | | 10 | s.close();↵
|
|
11 | s = openSession();↵ | | 11 | s = openSession();↵
|
12 | t = s.beginTransaction();↵ | | 12 | t = s.beginTransaction();↵
|
13 | c.getVariations().add( new ContractVariation(3, c) );↵ | | 13 | c.getVariations().add( new ContractVariation(3, c) );↵
|
14 | try {↵ | | 14 | ↵
|
15 | s.update( c ↵ | | 15 | s.merge( c );↵
|
| | | 16 | try {↵
|
16 | );↵ | | 17 | t.commit();↵
|
17 | fail( "should have failed because reassociated object has a dirty collection");↵ | | 18 | fail( "should have failed because an immutable collection was changed");↵
|
18 | }↵ | | 19 | }↵
|
19 | catch ( HibernateException ex ) {↵ | | 20 | catch ( HibernateException ex ) {↵
|
20 | // expected↵ | | 21 | // expected↵
|
21 | }↵ | | 22 | ↵
|
22 | finally {↵ | | |
|
23 | t.rollback();↵ | | 23 | t.rollback();↵
|
| | | 24 | }↵
|
| | | 25 | finally {↵
|
24 | s.close();↵ | | 26 | s.close();↵
|
25 | }↵ | | 27 | }↵
|
|
26 | s = openSession();↵ | | 28 | s = openSession();↵
|
27 | t = s.beginTransaction();↵ | | 29 | t = s.beginTransaction();↵
|
28 | c = (Contract) s.createCriteria(Contract.class).uniqueResult();↵ | | 30 | c = (Contract) s.createCriteria(Contract.class).uniqueResult();↵
|
29 | assertEquals( c.getCustomerName(), "gavin" );↵ | | 31 | assertEquals( c.getCustomerName(), "gavin" );↵
|
30 | assertEquals( c.getVariations().size(), 2 );↵ | | 32 | assertEquals( c.getVariations().size(), 2 );↵
|
31 | Iterator it = c.getVariations().iterator();↵ | | 33 | Iterator it = c.getVariations().iterator();↵
|
32 | cv1 = (ContractVariation) it.next();↵ | | 34 | cv1 = (ContractVariation) it.next();↵
|
33 | assertEquals( cv1.getText(), "expensive" );↵ | | 35 | assertEquals( cv1.getText(), "expensive" );↵
|
34 | cv2 = (ContractVariation) it.next();↵ | | 36 | cv2 = (ContractVariation) it.next();↵
|
35 | assertEquals( cv2.getText(), "more expensive" );↵ | | 37 | assertEquals( cv2.getText(), "more expensive" );↵
|
36 | s.delete(c);↵ | | 38 | s.delete(c);↵
|
37 | assertEquals( s.createCriteria(Contract.class).setProjection( Projections.rowCount() ).uniqueResult(), new Integer(0) );↵ | | 39 | assertEquals( s.createCriteria(Contract.class).setProjection( Projections.rowCount() ).uniqueResult(), new Integer(0) );↵
|
38 | assertEquals( s.createCriteria(ContractVariation.class).setProjection( Projections.rowCount() ).uniqueResult(), new Integer(0) );↵ | | 40 | assertEquals( s.createCriteria(ContractVariation.class).setProjection( Projections.rowCount() ).uniqueResult(), new Integer(0) );↵
|
39 | t.commit();↵ | | 41 | t.commit();↵
|
40 | s.close(); | | 42 | s.close();
|