【发布时间】:2011-06-21 10:49:05
【问题描述】:
我有实体对象:
@Entity
public class Tag {
@Id
private Long id;
@Transient
private int count;
// getter, setter etc..
}
@Entity
public class Request {
// fileds
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private Set<Tag> tag = new HashSet<Tag>();
// getter, setter etc..
}
我需要通过请求获取所有带有计数的标签。
在 DAO 中,我使用 SQL 查询为它创建函数:
select tag as id, count(rt.request) as count
from request_tag rt
where rt.request in (...) and rt.request in (...) and etc...
group by rt.tag order by count desc
已找到标签,但计数未绑定。
如何从查询中绑定计数?
PS:
我不想删除 @Transient 注释(因为我不想在 DB 中保留计数)。
我不想使用@Formula(因为它会很慢)。
【问题讨论】:
标签: java sql hibernate annotations hql