2017-03-02 14 views
0

org.hibernate.QueryExceptionのperson.name:プロパティを解決できませんでした:com.example.Scholarship時折org.hibernate.QueryException:プロパティを解決できませんでした:com.example.Scholarship

のperson.name

マイエンティティ奨学金にはフィールド「人」(エンティティPerson)があり、フィールド「name」(String)を持っています。 データベースで単純な選択を実行するためにCriteriaを使用すると、この例外が発生します。

org.hibernate.QueryException:プロパティを解決できませんでした:ここcom.example.Scholarship

のperson.nameは、私が選択を実行するために使用する方法である:

public <T> Collection<T> findAll(Class<T> classe, PagingInformation paging, String orderField, String orderType) throws DAOException { 
    Long total = (Long) getSession().createQuery("select count(*) from " + classe.getName()).uniqueResult(); 

    if (paging != null) { 
     paging.setTotalRegistros((int) total.longValue()); 
    } 

    Criteria c = getCriteria(classe); 
    c.setCacheable(true); 
    if (paging != null) { 
     c.setFirstResult(paging.getPaginaAtual() * paging.getTamanhoPagina()); 
     c.setMaxResults(paging.getTamanhoPagina()); 
    } 
    if (orderType.equals("asc")) { 
     c.addOrder(Order.asc(orderField)); 
    } else { 
     c.addOrder(Order.desc(orderField)); 
    } 
    return c.list(); 
} 

私が渡していますorderField String "person.name"とorderType "asc"です。ポイントは、Personは別のフィールド、id(long)を持っています。私は "person.id"を渡すとうまく動作します。何が問題なの?私は基準を使用して並べ替えを実行するためにフィールドのフィールドを使用することはできませんでしたか?

p.s:問題は、大文字またはスペルミスのこの種ではない、私はちょうど、すべてのゲッターメソッドを得ました。

+0

生成されたクエリを投稿できますか? –

+0

クエリが生成される前に例外がスローされます。 –

答えて

0

ScholarshipPersonの間にjoinを作成し、その結合を使用してnameフィールドで注文することができます。