何时使用Hibernate投影? [英] When to use Hibernate projections?

查看:144
本文介绍了何时使用Hibernate投影?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Hibernate的投影条件有点困惑。何时使用预测和何时使用标准?



请帮助我。
Thanks!

解决方案

它们并不相互排斥,您可以同时使用两者。预测通常用在一些Criteria的上下文中。

简单来说,Hibernate Projections用于查询实体或组的一个属性子集您正在使用Criteria查询的实体。您还可以使用Projections指定 distinct 子句和聚合函数,如 max sum 等等。这就像是指您要提取的数据。与修改类似,在SQL查询中选择子句。



Hibernate Criteria用于定义数据必须满足的条件以便被选中。这就像是指如何是您要获取的数据。像修改中的其中 SQL查询的子句。



请注意, 不完全正确,它只是一个旨在帮助OP的方向。例如,您可以使用 createCriteria(String associationPath)来更改要获取哪个数据。



我建议看看这篇文章 Hibernate:标准查询深度


I am a little confused about Hibernate's projections and criteria. When to use projections and when to use criteria?

Please help me. Thanks!

解决方案

They're not mutually exclusive, you can use both at the same time. Projections are generally used in the context of some Criteria.

To put it simple, Hibernate Projections are used in order to query only a subset of the attributes of an entity or group of entities you're querying with Criteria. You can also use Projections to specify distinct clauses and aggregate functions like max, sum and so on. It's like referring to which data you're fetching. Like modifying the select clause in an SQL query.

Hibernate Criteria are used to define conditions the data has to satisfy in order to be selected. It's like referring to how is the data you're fetching. Like modifiying the from and where clauses of an SQL query.

Note that this how and which is not strictly true, it's just an orientation aimed to aid the OP. You can change which data you're fetching with createCriteria(String associationPath) for instance.

I'd suggest to take a look at this article Hibernate: Criteria Queries in Depth

这篇关于何时使用Hibernate投影?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆