我得到“参数类型不匹配”的 sum 函数映射到非托管 jpa 实体。
查询:
final Path<String> departmentPath = root.get(SomeEntity_.department);
final Path<Status> statusPath = root.get(SomeEntity_.status);
final Predicate statusActivePred = cb.equal(statusPath, Status.ACTIVE);
final Expression<Integer> activeExp = cb.<Integer> selectCase().when(statusActivePred, Integer.valueOf(1)).otherwise(Integer.valueOf(0));
final Expression<Integer> sumActiveExp = cb.sum(activeExp );
query.select(cb.construct(SomeInfo.class, departmentPath, sumActiveExp));
...
映射类:
public class SomeInfo
{
private final String department;
private final Integer someCount;
public SomeInfo(final String department)
{
super();
this.department= department;
}
public SomeInfo(final String department, final Integer someCount)
{
super();
this.department= department;
this.someCount = someCount;
}
...
例外
java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.eclipse.persistence.internal.security.PrivilegedAccessHelper.invokeConstructor(PrivilegedAccessHelper.java:389)
at org.eclipse.persistence.queries.ReportQueryResult.buildResult(ReportQueryResult.java:121)
at org.eclipse.persistence.queries.ReportQueryResult.<init>(ReportQueryResult.java:78)
at org.eclipse.persistence.queries.ReportQuery.buildObject(ReportQuery.java:593)
at org.eclipse.persistence.queries.ReportQuery.buildObjects(ReportQuery.java:644)
at org.eclipse.persistence.queries.ReportQuery.executeDatabaseQuery(ReportQuery.java:847)
at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:852)
像下面这样的东西有效,但不是 sum 函数的表达式
query.select(cb.construct(SomeInfo.class, departmentPath));
有什么提示吗?