We started Quarkus 3 project with hibernate reactive. We tried panache implementation .project() but it is not working as expected. Is there any solution for this problem? Is possible to manually do projection or something?
Error:
java.lang.IllegalStateException: Could not determine appropriate instantiation strategy - no matching constructor found and one or more arguments did not define alias for bean-injection
at org.hibernate.sql.results.graph.instantiation.internal.DynamicInstantiationResultImpl.resolveAssembler(DynamicInstantiationResultImpl.java:197)
at org.hibernate.sql.results.graph.instantiation.internal.DynamicInstantiationResultImpl.createResultAssembler(DynamicInstantiationResultImpl.java:106)
Entities:
@Entity
@Table(name = "company")
public class CompanyEntity extends PanacheEntity {
private String name;
private String address;
@OneToMany(mappedBy = "company", targetEntity = DepartmentEntity.class,
cascade = CascadeType.ALL, fetch = FetchType.EAGER,
orphanRemoval = true)
private List<DepartmentEntity> departments = new ArrayList<>();
// getters and setters omitted for brevity
}
@Entity
@Table(name = "department")
public class DepartmentEntity extends PanacheEntity {
private String name;
private String description;
@JsonIgnore
@ManyToOne(fetch = FetchType.LAZY)
private CompanyEntity company;
// getters and setters omitted for brevity
}
DTOs
public class CompanyProjection {
private String name;
private List<DepartmentProjection> departments;
public CompanyProjection(String name, List<DepartmentProjection> departments) {
this.name = name;
this.departments = departments;
}
// getters and setters omitted for brevity
}
public class DepartmentProjection {
private String description;
public DepartmentProjection(String description) {
this.description = description;
}
// getters and setters omitted for brevity
}
Related repository method:
@ApplicationScoped
public class CompanyRepository implements PanacheRepository<CompanyEntity> {
// ...
@WithSession
public Uni<List<CompanyProjection>> getCompanyProjections() {
return findAll().project(CompanyProjection.class).list();
}
}
Code sample is available on GitHub.