1

管理されていない jpa エンティティへの sum-function マッピングで「引数の型の不一致」が発生しています。

クエリ:

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));

ヒントはありますか?

4

1 に答える 1

2

LongJPQLと一致しているため、 が返されると思います。JPA 2.0 仕様では、SUM 関数は次のように記述されています。

SUM は、(BigInteger 以外の) 整数型の状態フィールドに適用されると、Long を返します。浮動小数点型の状態フィールドに適用された場合は double。BigInteger 型の状態フィールドに適用された場合は BigInteger。および BigDecimal タイプの状態フィールドに適用される場合は BigDecimal。

また、Hibernate はそのように動作するようで、戻り値の型はLongです。

が優先される場合Long、戻り型はEclipseLinkでも影響を受ける可能性があります。それはCriteriaBuilder.sumAsLongを介して行うことができます:

final Expression<Long> sumActiveExp = cb.sumAsLong(activeExp);
于 2013-08-27T21:30:13.347 に答える