diff --git a/hibernate-core/src/matrix/java/org/hibernate/test/cid/CompositeIdTest.java b/hibernate-core/src/matrix/java/org/hibernate/test/cid/CompositeIdTest.java index e79e939c43..4ffd0fa3ba 100755 --- a/hibernate-core/src/matrix/java/org/hibernate/test/cid/CompositeIdTest.java +++ b/hibernate-core/src/matrix/java/org/hibernate/test/cid/CompositeIdTest.java @@ -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(); @@ -55,7 +82,7 @@ public class CompositeIdTest extends BaseCoreFunctionalTestCase { t.commit(); s.close(); } - + @Test public void testCompositeIds() { Session s = openSession();