public void testMultiPathMergeNonCascadedTransientEntityInCollection() throws Exception { // persist a simple A in the database Session s = openSession(); s.beginTransaction(); A a = new A(); a.setData( "Anna" ); s.save( a ); s.getTransaction().commit(); s.close(); // modify detached entity modifyEntity( a ); s = openSession(); s.beginTransaction(); a = ( A ) s.merge( a ); s.getTransaction().commit(); s.close(); verifyModifications( a.getId() ); // add a new (transient) G to collection in h // there is no cascade from H to the collection, so this should fail when merged assertEquals( 1, a.getHs().size() ); H h = ( H ) a.getHs().iterator().next(); G gNew = new G(); gNew.setData( "Gail" ); gNew.getHs().add( h ); h.getGs().add( gNew ); s = openSession(); s.beginTransaction(); try { s.merge( a ); s.merge( h ); fail( "should have thrown TransientObjectException" ); } catch ( TransientObjectException ex ) { // expected } finally { s.getTransaction().rollback(); } s.close();
public void testMultiPathMergeNonCascadedTransientEntityInManyToOne() throws Exception { // persist a simple A in the database Session s = openSession(); s.beginTransaction(); A a = new A(); a.setData( "Anna" ); s.save( a ); s.getTransaction().commit(); s.close(); // modify detached entity modifyEntity( a ); s = openSession(); s.beginTransaction(); a = ( A ) s.merge( a ); s.getTransaction().commit(); s.close(); verifyModifications( a.getId() ); // change the many-to-one association from h to be a new (transient) A // there is no cascade from H to A, so this should fail when merged assertEquals( 1, a.getHs().size() ); H h = ( H ) a.getHs().iterator().next(); a.getHs().remove( h ); A aNew = new A(); aNew.setData( "Alice" ); aNew.addH( h ); s = openSession(); s.beginTransaction(); try { s.merge( a ); s.merge( h ); fail( "should have thrown TransientObjectException" ); } catch ( TransientObjectException ex ) { // expected } finally { s.getTransaction().rollback(); } s.close();
Clone fragments detected by clone detection tool
File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/cascade/MultiPathCascadeTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/cascade/MultiPathCascadeTest.java
Method name: Method name:
Number of AST nodes: 0 Number of AST nodes: 0
1
public void testMultiPathMergeNonCascadedTransientEntityInCollection() throws Exception
1
public void testMultiPathMergeNonCascadedTransientEntityInManyToOne() throws Exception
2
	{
2
	{
3
		// persist a simple A in the database
3
		// persist a simple A in the database
4
		Session s = openSession();
4
		Session s = openSession();
5
		s.beginTransaction();
5
		s.beginTransaction();
6
		A a = new A();
6
		A a = new A();
7
		a.setData( "Anna" );
7
		a.setData( "Anna" );
8
		s.save( a );
8
		s.save( a );
9
		s.getTransaction().commit();
9
		s.getTransaction().commit();
10
		s.close();
10
		s.close();
11
		// modify detached entity
11
		// modify detached entity
12
		modifyEntity( a );
12
		modifyEntity( a );
13
		s = openSession();
13
		s = openSession();
14
		s.beginTransaction();
14
		s.beginTransaction();
15
		a = ( A ) s.merge( a );
15
		a = ( A ) s.merge( a );
16
		s.getTransaction().commit();
16
		s.getTransaction().commit();
17
		s.close();
17
		s.close();
18
		verifyModifications( a.getId() );
18
		verifyModifications( a.getId() );
19
		// add a new (transient) G to collection in h
19
		// change the many-to-one association from h to be a new (transient) A
20
		// there is no cascade from H to the collection, so this should fail when merged
20
		// there is no cascade from H to A, so this should fail when merged
21
		assertEquals( 1, a.getHs().size() );
21
		assertEquals( 1, a.getHs().size() );
22
		H h = ( H ) a.getHs().iterator().next();
22
		H h = ( H ) a.getHs().iterator().next();
23
		G g
23
		a.getHs().remove( h );
24
New = new G();
24
		A aNew = new A();
25
		gNew.setData( "Gail" );
25
		aNew.setData( "Alice" );
26
		gNew.getHs().add( h );
26
		aNew.addH( h );
27
		h.getGs().add( gNew );
28
		s = openSession();
27
		s = openSession();
29
		s.beginTransaction();
28
		s.beginTransaction();
30
		try {
29
		try {
31
			s.merge( a );
30
			s.merge( a );
32
			s.merge( h );
31
			s.merge( h );
33
			fail( "should have thrown TransientObjectException" );
32
			fail( "should have thrown TransientObjectException" );
34
		}
33
		}
35
		catch ( TransientObjectException ex ) {
34
		catch ( TransientObjectException ex ) {
36
			// expected
35
			// expected
37
		}
36
		}
38
		finally {
37
		finally {
39
			s.getTransaction().rollback();
38
			s.getTransaction().rollback();
40
		}
39
		}
41
		s.close();
40
		s.close();
42
	
41
	
Summary
Number of common nesting structure subtrees0
Number of refactorable cases0
Number of non-refactorable cases0
Time elapsed for finding largest common nesting structure subtrees (ms)0.0
Clones location
Number of node comparisons0