Hibernate中bag标签的用途是什么?

时间:2022-11-30 16:57:50

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

我需要知道如何使用bag标签,它的目的是什么?

3 个解决方案

#1


8  

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 。从数据库中检索包时,包不会保留其顺序,但可以选择对其进行排序或排序。

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

#2


3  

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。

#3


2  

A short and simple answer:

一个简短而简单的答案:

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

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

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

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

#1


8  

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 。从数据库中检索包时,包不会保留其顺序,但可以选择对其进行排序或排序。

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

#2


3  

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。

#3


2  

A short and simple answer:

一个简短而简单的答案:

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

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

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

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