1 | public void testImmutableChildEntityWithUpdate() {↵ | | 1 | public void testImmutableChildEntityWithMerge() {↵
|
2 | Contract c = new Contract("gavin", "phone");↵ | | 2 | Contract c = new Contract("gavin", "phone");↵
|
3 | ContractVariation cv1 = new ContractVariation(1, c);↵ | | 3 | ContractVariation cv1 = new ContractVariation(1, c);↵
|
4 | cv1.setText("expensive");↵ | | 4 | cv1.setText("expensive");↵
|
5 | ContractVariation cv2 = new ContractVariation(2, c);↵ | | 5 | ContractVariation cv2 = new ContractVariation(2, c);↵
|
6 | cv2.setText("more expensive");↵ | | 6 | cv2.setText("more expensive");↵
|
7 | Session s = openSession();↵ | | 7 | Session s = openSession();↵
|
8 | Transaction t = s.beginTransaction();↵ | | 8 | Transaction t = s.beginTransaction();↵
|
9 | s.persist(c);↵ | | 9 | s.persist(c);↵
|
10 | t.commit();↵ | | 10 | t.commit();↵
|
11 | s.close();↵ | | 11 | s.close();↵
|
|
12 | s = openSession();↵ | | 12 | s = openSession();↵
|
13 | t = s.beginTransaction();↵ | | 13 | t = s.beginTransaction();↵
|
14 | cv1 = (ContractVariation) c.getVariations().iterator().next();↵ | | 14 | cv1 = (ContractVariation) c.getVariations().iterator().next();↵
|
15 | cv1.setText("blah blah");↵ | | 15 | cv1.setText("blah blah");↵
|
16 | s.update( c );↵ | | 16 | s.merge( c );↵
|
17 | t.commit();↵ | | 17 | t.commit();↵
|
18 | s.close();↵ | | 18 | s.close();↵
|
|
19 | s = openSession();↵ | | 19 | s = openSession();↵
|
20 | t = s.beginTransaction();↵ | | 20 | t = s.beginTransaction();↵
|
21 | c = (Contract) s.createCriteria(Contract.class).uniqueResult();↵ | | 21 | c = (Contract) s.createCriteria(Contract.class).uniqueResult();↵
|
22 | assertEquals( c.getCustomerName(), "gavin" );↵ | | 22 | assertEquals( c.getCustomerName(), "gavin" );↵
|
23 | assertEquals( c.getVariations().size(), 2 );↵ | | 23 | assertEquals( c.getVariations().size(), 2 );↵
|
24 | Iterator it = c.getVariations().iterator();↵ | | 24 | Iterator it = c.getVariations().iterator();↵
|
25 | cv1 = (ContractVariation) it.next();↵ | | 25 | cv1 = (ContractVariation) it.next();↵
|
26 | assertEquals( cv1.getText(), "expensive" );↵ | | 26 | assertEquals( cv1.getText(), "expensive" );↵
|
27 | cv2 = (ContractVariation) it.next();↵ | | 27 | cv2 = (ContractVariation) it.next();↵
|
28 | assertEquals( cv2.getText(), "more expensive" );↵ | | 28 | assertEquals( cv2.getText(), "more expensive" );↵
|
29 | s.delete(c);↵ | | 29 | s.delete(c);↵
|
30 | assertEquals( s.createCriteria(Contract.class).setProjection( Projections.rowCount() ).uniqueResult(), new Integer(0) );↵ | | 30 | assertEquals( s.createCriteria(Contract.class).setProjection( Projections.rowCount() ).uniqueResult(), new Integer(0) );↵
|
31 | assertEquals( s.createCriteria(ContractVariation.class).setProjection( Projections.rowCount() ).uniqueResult(), new Integer(0) );↵ | | 31 | assertEquals( s.createCriteria(ContractVariation.class).setProjection( Projections.rowCount() ).uniqueResult(), new Integer(0) );↵
|
32 | t.commit();↵ | | 32 | t.commit();↵
|
33 | s.close();↵ | | 33 | s.close();↵
|
34 | | | 34 |
|