1

私は Java playframework 1.2.4 を使用してプロジェクトに取り組んでおり、 @Entity クラスを持っています。のようです

@Entity
public class EmployeeType extends Model {
    public static enum TYPE { HOURLY, DAILY, MONTHLY };
    public static enum NATIONALITY { LOCAL, FOREIGN };
    @Required
    @Enumerated(EnumType.STRING)
    public TYPE type;
    @Required
    @Enumerated(EnumType.STRING)
    public NATIONALITY nationality;
}

私のコントローラークラスでは、2 つの列挙型属性を使用して EmployeeTypes のリストを取得したいと考えています。クエリは次のようになります

Query query = JPA.em().createQuery("SELECT e FROM EmployeeType e where " +
            "e.nationality = :nationality " +
            "and e.type = :type");
query.setParameter("nationality", NATIONALITY.LOCAL);
query.setParameter("type", TYPE.HOURLY);

List<models.EmployeeType> employeeType = query.getResultList()

次のエラーが表示されます: IllegalArgumentException が発生しました: パラメータ値 [LOCAL] が型 [models.EmployeeType$NATIONALITY] と一致しませんでした

私は何をすべきか?

4

1 に答える 1

1

The error is possibly because of the fact that your enums are nested in your entity. You need to access it on entity name.

You can change your setParameter code to: -

query.setParameter("nationality", EmployeeType.NATIONALITY.LOCAL);
query.setParameter("type", EmployeeType.TYPE.HOURLY);
于 2013-02-05T13:02:04.833 に答える