4
通常、私はHibernateユーザーです。私の新しいプロジェクトでは、JPA 2.0を使用します。完全に動的にJPA基準を作成する
私のDAOは、汎用のコンテナを受け取ります。
if (">".equals(container.getOperation()) {
criteriaBuilder.greaterThan(root.get(container.getFieldId()), container.getValue());
}
ので私はこのようなタイプを指定する必要があります:
public class Container<T> {
private String fieldId; // example "id"
private T value; // example new Long(100) T is a Long
private String operation; // example ">"
// getter/setter
}
次の行はコンパイルされません
if (">".equals(container.getOperation()) {
criteriaBuilder.greaterThan(root.<Long>get(container.getFieldId()), (Long)container.getValue());
}
しかし、私はそれを行うにはしたくありません!私は自分のコンテナにジェネリックを使用しているからです! アイデアはありますか?限り、あなたのT
がComparable
あるよう