如何添加一个真正的查询的Hibernate属性 [英] How to add a Hibernate property that's really a query
问题描述
我们使用Hibernate来加载符合特定条件的对象。如果用户决定查看其中一个对象的详细信息,我想提取一些关于该对象的附加信息。我想要展示的一个属性将需要一个相当复杂的SQL查询,但计算结果是一个简单的布尔值。
We're using Hibernate to load objects that meet certain criteria. If the user decides to view the details on one of the objects, I want to pull up some additional information about the object. One of the "attributes" I'd like to show will require a fairly complex SQL query, but evaluates to a simple boolean.
什么是正确的方法休眠?有没有办法指出一个属性的值是SQL查询的结果?如果是这样,有没有办法阻止查询被调用,直到需要它?
What's the right way to do this with Hibernate? Is there a way to indicate a property whose value is the result of a SQL query? If so, is there a way to prevent the query from being invoked until it's needed?
或者我错误地处理了这个问题?
Or am I approaching this incorrectly?
推荐答案
根据查询的复杂程度和返回结果,可以使用公式或将您的属性映射为单独的实体(多对一),它将被延迟加载。
Depending on how complex that query is and what it returns, you can either use a formula or map your "attribute" as a separate entity (many-to-one) that will be lazy-loaded.
这篇关于如何添加一个真正的查询的Hibernate属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!