2

私はそのように宣言された「タグ」プロパティを持っています:

@Entity
public class BlogArticle
{
    [...]
    @ElementCollection(fetch = FetchType.EAGER)
    Set<String> tags =new HashSet<String>();
    [...]
}

このプロパティは、記事に関連付けられたタグを表します。次に、タグ クラウドを生成します。そこで、各タグの頻度を数えたいと思います。

それを行う簡単な方法はありますか?(Tag オブジェクトを作成せずに?)

4

1 に答える 1

2
String hql = "select t, count(1) from BlogArticle a inner join a.tags t group by t";
List tagCounts = createQuery( hql ).list();

Iterator itr = tagCounts.iterator();
while ( itr.hasNext() ) {
    Object[] tagCount = (Object[]) itr.next();
    String tag = (String) tagCount[0];
    Long count = (Long) tagCount[1];
}
于 2012-05-31T05:45:04.783 に答える