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?