Update of /cvsroot/hibernate/Hibernate3/test/org/hibernate/test/hql In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7958/test/org/hibernate/test/hql Modified Files: BulkManipulationTest.java SimpleEntityWithAssociation.hbm.xml SimpleEntityWithAssociation.java Log Message: HHH-1419 Index: BulkManipulationTest.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate3/test/org/hibernate/test/hql/BulkManipulationTest.java,v retrieving revision 1.51 retrieving revision 1.52 diff -u -d -r1.51 -r1.52 --- BulkManipulationTest.java 10 Feb 2006 17:30:40 -0000 1.51 +++ BulkManipulationTest.java 13 Feb 2006 15:50:52 -0000 1.52 @@ -82,6 +82,35 @@ s.close(); } + public void testTempTableGenerationIsolation() throws Throwable{ + Session s = openSession(); + s.beginTransaction(); + + Truck truck = new Truck(); + truck.setVin( "123t" ); + truck.setOwner( "Steve" ); + s.save( truck ); + + // manually flush the session to ensure the insert happens + s.flush(); + + // now issue a bulk delete against Car which should force the temp table to be + // created. we need to test to ensure that this does not cause the transaction + // to be committed... + s.createQuery( "delete from Vehicle" ).executeUpdate(); + + s.getTransaction().rollback(); + s.close(); + + s = openSession(); + s.beginTransaction(); + List list = s.createQuery( "from Car" ).list(); + assertEquals( "temp table gen caused premature commit", 0, list.size() ); + s.createQuery( "delete from Car" ).executeUpdate(); + s.getTransaction().rollback(); + s.close(); + } + // INSERTS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -375,6 +404,7 @@ // UPDATES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ public void testUpdateWithWhereExistsSubquery() { + // multi-table ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Session s = openSession(); Transaction t = s.beginTransaction(); Human joe = new Human(); @@ -403,6 +433,46 @@ s.delete( joe ); t.commit(); s.close(); + + // single-table (one-to-many & many-to-many) ~~~~~~~~~~~~~~~~~~~~~~~~~~ + s = openSession(); + t = s.beginTransaction(); + SimpleEntityWithAssociation entity = new SimpleEntityWithAssociation(); + SimpleEntityWithAssociation other = new SimpleEntityWithAssociation(); + entity.setName( "main" ); + other.setName( "many-to-many-association" ); + entity.getManyToManyAssociatedEntities().add( other ); + entity.addAssociation( "one-to-many-association" ); + s.save( entity ); + t.commit(); + s.close(); + + s = openSession(); + t = s.beginTransaction(); + // one-to-many test + updateQryString = "update SimpleEntityWithAssociation e " + + "set e.name = 'updated' " + + "where exists (" + + " select a.id " + + " from e.associatedEntities a " + + " where a.name = 'one-to-many-association' " + + ")"; + count = s.createQuery( updateQryString ).executeUpdate(); + assertEquals( 1, count ); + // many-to-many test + updateQryString = "update SimpleEntityWithAssociation e " + + "set e.name = 'updated' " + + "where exists (" + + " select a.id " + + " from e.manyToManyAssociatedEntities a " + + " where a.name = 'many-to-many-association' " + + ")"; + count = s.createQuery( updateQryString ).executeUpdate(); + assertEquals( 1, count ); + s.delete( entity.getManyToManyAssociatedEntities().iterator().next() ); + s.delete( entity ); + t.commit(); + s.close(); } public void testIncrementCounterVersion() { @@ -725,35 +795,6 @@ // DELETES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - public void testTempTableGenerationIsolation() throws Throwable{ - Session s = openSession(); - s.beginTransaction(); - - Truck truck = new Truck(); - truck.setVin( "123t" ); - truck.setOwner( "Steve" ); - s.save( truck ); - - // manually flush the session to ensure the insert happens - s.flush(); - - // now issue a bulk delete against Car which should force the temp table to be - // created. we need to test to ensure that this does not cause the transaction - // to be committed... - s.createQuery( "delete from Vehicle" ).executeUpdate(); - - s.getTransaction().rollback(); - s.close(); - - s = openSession(); - s.beginTransaction(); - List list = s.createQuery( "from Car" ).list(); - assertEquals( "temp table gen caused premature commit", 0, list.size() ); - s.createQuery( "delete from Car" ).executeUpdate(); - s.getTransaction().rollback(); - s.close(); - } - public void testDeleteWithSubquery() { // setup the test data... Session s = openSession(); Index: SimpleEntityWithAssociation.hbm.xml =================================================================== RCS file: /cvsroot/hibernate/Hibernate3/test/org/hibernate/test/hql/SimpleEntityWithAssociation.hbm.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- SimpleEntityWithAssociation.hbm.xml 13 Jan 2006 16:09:25 -0000 1.1 +++ SimpleEntityWithAssociation.hbm.xml 13 Feb 2006 15:50:52 -0000 1.2 @@ -15,6 +15,10 @@ <key column="SIMPLE_1_ID"/> <one-to-many class="SimpleAssociatedEntity"/> </set> + <set name="manyToManyAssociatedEntities" cascade="save-update" inverse="false" lazy="true" table="MANY_TO_MANY"> + <key column="IN_ID"/> + <many-to-many class="SimpleEntityWithAssociation" column="OUT_ID"/> + </set> </class> <class name="SimpleAssociatedEntity" table="SIMPLE_2"> Index: SimpleEntityWithAssociation.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate3/test/org/hibernate/test/hql/SimpleEntityWithAssociation.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- SimpleEntityWithAssociation.java 13 Jan 2006 16:09:25 -0000 1.1 +++ SimpleEntityWithAssociation.java 13 Feb 2006 15:50:52 -0000 1.2 @@ -10,6 +10,7 @@ private Long id; private String name; private Set associatedEntities = new HashSet(); + private Set manyToManyAssociatedEntities = new HashSet(); public SimpleEntityWithAssociation() { } @@ -58,4 +59,12 @@ throw new IllegalArgumentException( "SimpleAssociatedEntity [" + association + "] not currently bound to this [" + this + "]" ); } } + + public Set getManyToManyAssociatedEntities() { + return manyToManyAssociatedEntities; + } + + public void setManyToManyAssociatedEntities(Set manyToManyAssociatedEntities) { + this.manyToManyAssociatedEntities = manyToManyAssociatedEntities; + } } |