We're updating the issue view to help you get more done. 

"java.lang.IllegalStateException: No supertype found" thrown on query with "COUNT" aggregate function

Description

I have 2 entities:

1 2 3 4 5 6 7 8 @Entity public class Transaction { @Id @Column private Integer trId; ... }
1 2 3 4 5 6 7 8 9 10 11 12 13 @Entity public class Form { @Id @OneToOne @JoinColumn( name = "trId" ) private Transaction transaction; @Column private String firstname; ... }

And query:

1 2 3 4 5 6 7 8 9 10 private EntityManager em; ... CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Long> c = cb.createQuery( Long.class ); Root<Form> form = c.from( Form.class ); c.select( cb.count( form ) ); TypedQuery<Long> q = em.createQuery( c ); int count = q.getResultList().get( 0 ).intValue();

Following exception was thrown on execution of "TypedQuery<Long> q = em.createQuery( c );":
Caused by: java.lang.IllegalStateException: No supertype found
at org.hibernate.ejb.metamodel.AbstractIdentifiableType.requireSupertype(AbstractIdentifiableType.java:85)
at org.hibernate.ejb.metamodel.AbstractIdentifiableType.getIdType(AbstractIdentifiableType.java:173)
at org.hibernate.ejb.criteria.expression.function.AggregationFunction$COUNT.renderArguments(AggregationFunction.java:110)
at org.hibernate.ejb.criteria.expression.function.ParameterizedFunctionExpression.render(ParameterizedFunctionExpression.java:94)
at org.hibernate.ejb.criteria.expression.function.BasicFunctionExpression.renderProjection(BasicFunctionExpression.java:71)
at org.hibernate.ejb.criteria.QueryStructure.render(QueryStructure.java:250)
at org.hibernate.ejb.criteria.CriteriaQueryImpl.render(CriteriaQueryImpl.java:338)
at org.hibernate.ejb.criteria.CriteriaQueryCompiler.compile(CriteriaQueryCompiler.java:216)
at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:623)

I think the problem is in the org.hibernate.ejb.metamodel.AbstractIdentifiableType.getIdType() function, which is not prepared for "mapped identifier" (as is org.hibernate.ejb.metamodel.MetadataContext.applyIdMetadata procedure).

Environment

None

Status

Assignee

Strong Liu

Reporter

Tomas Milo

Labels

Affects versions

4.1.1

Priority

Critical