带投影的 Hibernate 标准不会返回实施标准的实体
我正在使用 spring-hibernate 并使用 HibernateDAOSupport 类。 我有两个表以一对多的方式相互映射。 我正在实现以下标准,
DetachedCriteria criteria = getCriteria( "a" )
.setProjection( Projections.projectionList()
.add( Projections.groupProperty("a.id" ) )
.add( Projections.count( "a.id" ), "count" )
)
.createCriteria( "huApps", "hu")
.addOrder( Order.desc( "count" ) )
;
效果很好,并创建以下查询。
select
this_.id as y0_,
count(this_.id) as y1_
from
apps this_
inner join
huapps huapp1_
on this_.id=huapp1_.appid
group by
this_.id
order by
y1_ desc
结果,它返回一个 object[]
列表。但我希望它应该返回 List
(App 是我在其上实现/创建条件的类)。 我希望它会创建查询
select
this_
from
apps this_
inner join
huapps huapp1_
on this_.id=huapp1_.appid
group by
this_.id
order by
y1_ desc
请帮助我编写正确的条件。 我也尝试过 sqlProjection() ,但即使这样也不起作用。 我有什么办法可以实现这个目标吗?
I'm using spring-hibernate and using HibernateDAOSupport class.
I have two tables mapped to each other in one-to-many fashion.
I'm implementing the below criteria
DetachedCriteria criteria = getCriteria( "a" )
.setProjection( Projections.projectionList()
.add( Projections.groupProperty("a.id" ) )
.add( Projections.count( "a.id" ), "count" )
)
.createCriteria( "huApps", "hu")
.addOrder( Order.desc( "count" ) )
;
this works well and create the below query
select
this_.id as y0_,
count(this_.id) as y1_
from
apps this_
inner join
huapps huapp1_
on this_.id=huapp1_.appid
group by
this_.id
order by
y1_ desc
In result, it returns a list of object[]
. But I want that it should return List<App>
(App is the class on which I implemented/created the criteria).
I want that it would create the query
select
this_
from
apps this_
inner join
huapps huapp1_
on this_.id=huapp1_.appid
group by
this_.id
order by
y1_ desc
Please help me in writing the correct criteria.
I also tried with sqlProjection()
but even that didn't work.
Is there any way I can achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您尝试为
detachedCriteria.createCriteria("huApps", "hu") 函数结果的新标准添加组织。该函数返回 huApp 属性类的新标准。
尝试替换这样的标准:
它对我来说效果很好。
You try to add orger for new critheria that is result of function
detachedCriteria.createCriteria("huApps", "hu")
. This function return the new criteria for class of huApp property.Try to replace you criteria like this:
It works well for me.
尝试调用
这应该将属性别名映射到您指定的 bean 的字段。应用程序将需要在适当的字段上设置和获取方法
Try calling
This should map the properties alias to the fields of the bean that you specify. App will need setters and getters on the appropriate fields