0

我有一个联想,就这么简单:人与人之间的友谊联想;

@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 ;

但是 hql 如何获得可嵌入的 bean 呢?我用

 select fs from  Friendship fs where fs.year >2;

但抛出异常

exception:org.hibernate.hql.ast.QuerySyntaxException: Friendship  is not mapped 
4

0 回答 0