0

私は3つのクラスの次の関係を持っています:

   @Entity
    public class User{

       @OnetoMany
       List<Attribute> attributes = new ArrayList<Attribute>();
    }

    @Entity
    public class Attribute{
       @ManyToOne
       AttributeType attributeType;

    }

    @Entity
    public class AttributeType{

       @Column
       String type;
    }

1 人のユーザーは、m 型の n 属性を持つことができます。

List<AttributeType>特定のユーザー属性のすべての属性タイプを返す HQL クエリを作成する必要があります。

たとえば、ユーザーは、タイプ t の属性 a、タイプ t の属性 b、およびタイプ t1 の属性 c を持っています。List<AttributeType>t と t1 を含むものを返す必要があります。

助けてください。このクエリで迷子になりました。

4

1 に答える 1

1

Attribute を User に多対 1 の関係でマップする必要があるため、次のクエリが必要になります。

select distinct atr.attributeType
  from Attribute atr
 where atr.user = :user

次のクエリも機能すると思います。

select distinct atrs.attributeType
  from User as user
  join user.attributes as atrs   
 where user.id = :user_id
于 2012-08-29T22:59:09.827 に答える