Create Query - No superclass fields found

hibernate-core - 6.1.7.Final

Root class:

@Data
@Entity
@Table(name = "pet")
@EqualsAndHashCode(callSuper = true)
public class Pet extends BaseManualUuidEntity {

    @Column(name = "name")
    private String name;
}

Extended Class

@Getter
@Setter
@MappedSuperclass
public abstract class BaseManualUuidEntity {

    @Id
    @Column(name = "ID", unique = true, nullable = false)
    protected UUID id;
}
        final CriteriaBuilder cb = entityManager.getCriteriaBuilder();
        final CriteriaQuery<Pet> cq = cb.createQuery(Pet.class);
        final Root<Pet> root = cq.from(Pet.class);

        final List<Selection<?>> selections = Lists.newArrayList();
        selections.add(root.get("id").alias("id"));
        selections.add(root.get("name").alias("name"));
        cq.multiselect(selections);

        final List<Predicate> predicates = Lists.newArrayList(
                cb.equal(root.get("id"), UUID.fromString("358d67a6-87ad-4fd7-9348-b8247a60cd29")),
                cb.equal(root.get("name"), "Ronaldo")
        );
       cq.where(Iterables.toArray(predicates, Predicate.class));

      final List<Pet> resultList = entityManager.createQuery(cq).getResultList();

After running the code, it receives an error:

org.hibernate.query.sqm.sql.internal.InstantiationException: Unable to determine dynamic instantiation injection strategy for pl.esp.hibernate.model.Pet#id

After analyzing the errors, I arrive at such a place in the org.hibernate.sql.results.graph.instantiation.internal.DynamicInstantiationAssemblerInjectionImpl class.
There follows a verification of the availability of fields only in the main class. How to deal with this?

In version 6.3.0.CR1 I have a similar problem, just a different error.

org.hibernate.query.sqm.sql.internal.InstantiationException: Cannot set field 'id' to instantiate 'pl.esp.hibernate.model.Pet'

Seems like you found a bug. Please create an issue in the issue tracker(https://hibernate.atlassian.net) with a test case(https://github.com/hibernate/hibernate-test-case-templates/blob/master/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java) that reproduces the issue.

@beikov Was this issue already resolved?

Since @Ghan didn’t post the Jira issue key I have no idea, but maybe just try out the latest version 6.3.1.Final or 6.4.0.CR1 and report back.

I checked both 6.3.1.Final or 6.4.0.CR1 and this exception is still thrown:

org.hibernate.query.sqm.sql.internal.InstantiationException: Cannot set field '...' to instantiate ...

For project where stability is important is it better to use hibernate criteria api or hql instead of jpa criteria api?

In that case, since @Ghan didn’t do it, please create a Jira ticket and attach a reproducer that shows this problem based on our test case template.

@beikov Done

https://hibernate.atlassian.net/browse/HHH-17382

1 Like

thank you for share with us.