0

getValueByLabelメソッドを使用して簡単なクエリを作成したい:

これが私のコードです:

public Config getValueByLabel(String label) throws EntityPersistException{

    try {
        Query query = em.createQuery("select id from config where config_label=:label",Long.class);
        query.setParameter("label", label);
        List<Long> config = query.getResultList();

        return em.getReference(Config.class, config.get(0));
    }
...

メソッドを開始したいときは、次のようになります。

org.hibernate.hql.internal.ast.QuerySyntaxException: config is not mapped [select id from config where config_label=:label]

それを修正する方法はありますか?

アップデート

私は使っている:

hibernate 4.0.1.Final と postgresql db 1.16.1

4

1 に答える 1

0

hql の構文では、大文字と小文字が区別されます。クエリで使用されるテーブル/エンティティおよび列/インスタンスの変数名がオブジェクトの名前と同じかどうかを確認してください。

于 2013-05-04T09:55:49.000 に答える