私には次のような単純な関係があります。人々の間の友好関係。
@JoinTable(name = "friendship", joinColumns = @JoinColumn(name = "people1_id"))
@MapKeyManyToMany(targetEntity = People.class, joinColumns = @JoinColumn(name = "people2_id"))
@Column(name = "a_value")
public Map<People, Friendship> getFriendship() {
return friendshipInfos;
}
@embeddable
class Friendship {
Long years ;
}
テーブル :
friendship {
people1_id bigint(20) NOT NULL;
people2_id bigint(20) NOT NULL;
years tinyint(3) NOT NULL;
}
hqlを使用して友情情報を直接検索するにはどうすればよいですか。人の情報は必要ありません。私が知っているSQLを使用して:
select count(*) from friendship fs where fs.year >2 ;
しかし、埋め込み可能な Bean を取得するために hql はどのように行うのでしょうか? 私が使う
select fs from Friendship fs where fs.year >2;
しかし、例外をスローします
exception:org.hibernate.hql.ast.QuerySyntaxException: Friendship is not mapped