本文介绍了是否有可能在Hibernate中使用分析函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
类似于
<$ p 有没有办法像Hibernate中的分析函数一样使用sql-server? $ p $
从foo foo中选择foo其中fx = max(fx)over(用fy分区)
查询q = em.createNativeQuery(select foo。* from Foo foo+
where fx = max(fx )over+
(由fy分区),Foo.class);
如果您需要返回多个类型,请查看注释。
如果您直接使用Hibernate API:
Query q = session.createSQLQuery(select {foo。*}来自Foo foo+
,其中fx = max(fx)超过+
(由fy划分));
q.addEntity(foo,Foo.class);
请参阅以获得更多细节。
在这两个API中,您都可以像使用setParameter一样正常传递参数。
Is there a way to use sql-server like analytic functions in Hibernate?
Something like
select foo from Foo foo where f.x = max(f.x) over (partition by f.y)
解决方案
You are after a native SQL query.
If you are using JPA the syntax is:
Query q = em.createNativeQuery("select foo.* from Foo foo " +
"where f.x = max(f.x) over " +
"(partition by f.y)", Foo.class);
If you need to return multiple types, take a look at the SQLResultSetMapping annotation.
If you're using the the Hibernate API directly:
Query q = session.createSQLQuery("select {foo.*} from Foo foo " +
"where f.x = max(f.x) over "+
"(partition by f.y)");
q.addEntity("foo", Foo.class);
See 10.4.4. Queries in native SQL in the Hibernate documentation for more details.
In both APIs you can pass in parameters as normal using setParameter.
这篇关于是否有可能在Hibernate中使用分析函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!