获取属性中列表的大小

发布于 2024-08-22 09:18:53 字数 221 浏览 3 评论 0原文

我有一个 A 类,其中有 B 元素列表。

在我的 A 类中,我想添加:

int size;

它将根据 B 元素的数量进行评估。因此,当我调用 myA.getSize() 时,我就会得到它。

是否可以在休眠映射中使用单个属性来映射计数查询?

我不想加载列表,这就是我想添加尺寸属性的原因。

I have a class A which have a list of B elements.

In my A class i would like to add:

int size;

which will be valued with the number of B elements. So when I would call myA.getSize() I will have it.

Is it possible to map a count query with a single property in the hibernate mapping?

I don't want to load the list that is why i would like to add a size property.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

仙气飘飘 2024-08-29 09:18:53

是否可以在休眠映射中使用单个属性来映射计数查询?

是的,使用公式

<property name="size" type="integer"
formula="( select count(a.getBs) from A a where a.id = aid )">
</property>

更多示例参见 示例:各种映射< /a>.

Is it possible to map a count query with a single property in the hibernate mapping?

Yes, use a formula:

<property name="size" type="integer"
formula="( select count(a.getBs) from A a where a.id = aid )">
</property>

More examples in Example: Various Mappings.

电影里的梦 2024-08-29 09:18:53

另一种方法是在集合上使用lazy=extra参考文档中几乎没有提到这一点 并在此处进一步解释。

在集合上使用lazy="extra"
“智能”收集行为,即一些
集合操作,例如 size()、
contains()、get()等不触发
集合初始化。这是
仅适用于非常大的情况
收藏。

Another approach is to use lazy=extra on the collection. This is barely mentioned in the reference documentation and explained further here.

Use lazy="extra" on collections for
"smart" collection behavior, i.e. some
collection operations such as size(),
contains(), get(), etc. do not trigger
collection initialization. This is
only sensible for very large
collections.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文