HHH-7165 - count() query on classes using EmbeddedId should not use id column tuple on Dialects which dont support non-distinct tuple counts

This commit is contained in:
Steve Ebersole 2012-03-13 11:57:59 -05:00
parent c943285bbd
commit 41dd7079e0
1 changed files with 28 additions and 1 deletions

View File

@ -24,6 +24,7 @@
package org.hibernate.test.cid;
import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
@ -32,6 +33,9 @@ import org.junit.Test;
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.engine.query.spi.HQLQueryPlan;
import org.hibernate.hql.spi.QueryTranslator;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import static org.junit.Assert.assertEquals;
@ -47,6 +51,29 @@ public class CompositeIdTest extends BaseCoreFunctionalTestCase {
return new String[] { "cid/Customer.hbm.xml", "cid/Order.hbm.xml", "cid/LineItem.hbm.xml", "cid/Product.hbm.xml" };
}
@Test
public void testNonDistinctCountOfEntityWithCompositeId() {
// the check here is all based on whether we had commas in the expressions inside the count
final HQLQueryPlan plan = sessionFactory().getQueryPlanCache().getHQLQueryPlan(
"select count(o) from Order o",
false,
Collections.EMPTY_MAP
);
assertEquals( 1, plan.getTranslators().length );
final QueryTranslator translator = plan.getTranslators()[0];
final String generatedSql = translator.getSQLString();
final int countExpressionListStart = generatedSql.indexOf( "count(" );
final int countExpressionListEnd = generatedSql.indexOf( ")", countExpressionListStart );
final String countExpressionFragment = generatedSql.substring( countExpressionListStart+6, countExpressionListEnd+1 );
final boolean hadCommas = countExpressionFragment.contains( "," );
// set up the expectation based on Dialect...
final boolean expectCommas = sessionFactory().getDialect().supportsTupleCounts();
assertEquals( expectCommas, hadCommas );
}
@Test
public void testQuery() {
Session s = openSession();