HHH-7216 'java.lang.IllegalStateException: No supertype found' thrown on query with COUNT aggregate function
This commit is contained in:
parent
858c68364a
commit
4f2088856f
|
@ -115,7 +115,7 @@ public class AggregationFunction<T>
|
|||
Expression argExpr = argExprs.get(0);
|
||||
if (argExpr instanceof Root<?>) {
|
||||
Root<?> root = (Root<?>)argExpr;
|
||||
if (root.getModel().getIdType() != null) {
|
||||
if (!root.getModel().hasSingleIdAttribute()) {
|
||||
buffer.append('*');
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import java.util.List;
|
|||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Expression;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import javax.persistence.criteria.Root;
|
||||
|
||||
|
@ -143,6 +144,37 @@ public class IdClassPredicateTest extends AbstractMetamodelSpecificTest {
|
|||
em.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCountIdClassAttributes(){
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
CriteriaBuilder cb = em.getCriteriaBuilder();
|
||||
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
|
||||
Root<Widget> path = cq.from(Widget.class);
|
||||
Expression<Long> countSelection = cb.count(path);
|
||||
cq.select(countSelection);
|
||||
Long count = em.createQuery(cq).getSingleResult();
|
||||
// // Packaging arguments for use in query.
|
||||
// List<String> divisions = new ArrayList<String>( );
|
||||
// divisions.add( "NA" );
|
||||
// divisions.add( "EU" );
|
||||
//
|
||||
// // Building the query.
|
||||
// CriteriaBuilder criteria = em.getCriteriaBuilder( );
|
||||
// CriteriaQuery<Widget> query = criteria.createQuery( Widget.class );
|
||||
// Root<Widget> root = query.from( Widget.class );
|
||||
//
|
||||
// Predicate predicate = root.get( "division" ).in( divisions );
|
||||
// query.where( predicate );
|
||||
//
|
||||
// // Retrieving query.;
|
||||
// List<Widget> widgets = em.createQuery( query ).getResultList( );
|
||||
// Assert.assertEquals( 4, widgets.size() );
|
||||
|
||||
em.getTransaction().commit();
|
||||
em.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDeclaredIdClassAttributes( ) {
|
||||
|
|
Loading…
Reference in New Issue