Update of /cvsroot/hibernate/Hibernate3/test/org/hibernate/test/hql
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31266/test/org/hibernate/test/hql
Modified Files:
ASTParserLoadingTest.java
Log Message:
HHH-1411 & HHH-1412 : in-memory application of DISTINCT and firstRow/maxRows in conjunction with collection fetches
Index: ASTParserLoadingTest.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -d -r1.53 -r1.54
--- ASTParserLoadingTest.java 16 Feb 2006 19:24:13 -0000 1.53
+++ ASTParserLoadingTest.java 16 Feb 2006 23:21:18 -0000 1.54
@@ -11,6 +11,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.HashSet;
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -67,6 +68,53 @@
};
}
+ public void testCollectionFetchWithDistinctionAndLimit() {
+ // create some test data...
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ int parentCount = 30;
+ for ( int i = 0; i < parentCount; i++ ) {
+ Animal child1 = new Animal();
+ child1.setDescription( "collection fetch distinction (child1 - parent" + i + ")" );
+ s.persist( child1 );
+ Animal child2 = new Animal();
+ child2.setDescription( "collection fetch distinction (child2 - parent " + i + ")" );
+ s.persist( child2 );
+ Animal parent = new Animal();
+ parent.setDescription( "collection fetch distinction (parent" + i + ")" );
+ parent.setSerialNumber( "123-" + i );
+ parent.addOffspring( child1 );
+ parent.addOffspring( child2 );
+ s.persist( parent );
+ }
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ // Test simple distinction
+ List results;
+ results = s.createQuery( "select distinct p from Animal p inner join fetch p.offspring" ).list();
+ assertEquals( "duplicate list() returns", 30, results.size() );
+ // Test first/max
+ results = s.createQuery( "select p from Animal p inner join fetch p.offspring order by p.id" )
+ .setFirstResult( 5 )
+ .setMaxResults( 20 )
+ .list();
+ assertEquals( "duplicate returns", 20, results.size() );
+ Animal firstReturn = ( Animal ) results.get( 0 );
+ assertEquals( "firstResult not applied correctly", "123-5", firstReturn.getSerialNumber() );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ s.createQuery( "delete Animal where mother is not null" ).executeUpdate();
+ s.createQuery( "delete Animal" ).executeUpdate();
+ t.commit();
+ s.close();
+ }
+
public void testFetchInSubqueryFails() {
Session s = openSession();
try {
|