我有一个使用条件查询的 java spring 应用程序。该查询具有多选,其中一个值是带来完整实体的子查询。该应用程序在我们创建它的原始环境中运行,但我们尝试在新环境中运行并更新了一些库,但现在不起作用。
案例示例
@Entity
public class User {
private Long id;
private String name;
private String lastName;
}
@Entity
public class Address {
private Long id;
private String foo;
private String bar;
}
@Getter
@AllArgsConstructor
public class DataResultQuery {
private String name;
private String lastName;
private Address firstAddress;
private Address lastAddress;
}
public class Example {
public DataResultQuery getData(Long id) {
var builder = entityManager.getCriteriaBuilder();
var query = builder.createQuery(DataResultQuery.class);
var user = query.from(User.class);
var address = user.join(User_.addresses);
var firstAddress = getSubquery(address);
var lastAddress = getSubquery(address);
query.multiselect(
user.get(User_.name),
user.get(User_.lastName),
firstAddress.getSelection(),
lastAddress.getSelection()
);
query.where(); //Predicates
var typedQuery = entityManager.createQuery(query);
return typedQuery.getSingleResult();
}
private Subquery<Address> getSubquery(Join<?, Address> address) {
var builder = entityManager.getCriteriaBuilder();
var query = builder.createQuery(Address.class);
var subquery = query.subquery(Address.class);
var address = subquery.from(Address.class);
subquery.select(address);
subquery.where(); //Predicates
return subquery;
}
}
当我尝试执行查询时返回类似这样的内容
Cannot instantiate class 'com.package.example.result_queries.DataResultQuery' (it has no constructor with signature
我尝试搜索一些内容,但没有找到任何内容,并尝试手动创建完整的构造函数
尝试添加@NoArgConstructor,然后看看效果如何