java Hibernate中bag tag的作用是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3306833/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 01:13:46  来源:igfitidea点击:

What is the use of bag tag in Hibernate?

javahibernateormhibernate-mapping

提问by gokul

I need to know how to use the bag tag and what is the purpose of it?

我需要知道如何使用行李牌以及它的用途是什么?

回答by Damian Leszczyński - Vash

For collection mapping

用于集合映射

If your table does not have an index column, and you still wish to use List as the property type, you can map the property as a Hibernate < bag>. A bag does not retain its order when it is retrieved from the database, but it can be optionally sorted or ordered.

如果您的表没有索引列,并且您仍然希望使用 List 作为属性类型,则可以将该属性映射为 Hibernate < bag>。从数据库中检索包时不会保留其顺序,但可以选择对其进行排序或排序。

http://docs.jboss.org/hibernate/core/3.3/reference/en/html/collections.html

http://docs.jboss.org/hibernate/core/3.3/reference/en/html/collections.html

回答by McGin

From the API:

从API:

A bag is an unordered, unkeyed collection that can contain the same element multiple times. A bag permits duplicates, so it has no primary key. The Java collections API, curiously, has no Bag.

Bag 是一个无序、无键的集合,可以多次包含相同的元素。包允许重复,所以它没有主键。奇怪的是,Java 集合 API 没有 Bag。

回答by Rafael Borja

A short and simple answer:

一个简短的答案:

You don't need to use the <index>tag when mapping an unsorted Listand you also don't need an additional index column in database.

<index>映射未排序时不需要使用标记,List也不需要数据库中的额外索引列。

Unlike a List a Bag does not persist the order of its elements, but you can specify an order-byparameter to retrieve its elements in a specific order.

与 List 不同,Bag 不保留其元素的顺序,但您可以指定一个order-by参数以按特定顺序检索其元素。