1

基準を使用して、アクティブなユーザーを含む通知のリストを取得しています。問題は、次のエラーが発生することです。

org.hibernate.QueryException: could not resolve property: user.active of: com.company.Notification

それ以外の場合は、ユーザーがアクティブであることを確認する必要があります。通知が目的のタイプであることを確認する必要があります。これが私のコードです:

session.createCriteria("com.company.Notification")
    .add(Restrictions.or(Restrictions.eq("type", "email"), 
    .add(Restrictions.eq("user.active", true)).list();

通知にはフィールドがあり、そのフィールドUser userにはフィールドがありますBoolean active

私はこのページを見ています:https ://forum.hibernate.org/viewtopic.php?t = 948576&highlight = subproperty

しかし、私はまだ親オブジェクトと子オブジェクトの何かにアクセスする基準を作成する方法を模索していません。

4

1 に答える 1

6

これを試して:

session.createCriteria("com.company.Notification")
    .add(Restrictions.or(Restrictions.eq("type", "email")
    .createCriteria("user") // this creates the join on the user table...
    .add(Restrictions.eq("active", true)).list();

それが役に立ったことを願っています...

于 2010-11-22T21:07:33.207 に答える