Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Collection Bag wtih annotation

Tags:

java

hibernate

I'm watching a good video made by Burt Beckwith

http://www.infoq.com/presentations/GORM-Performance

he says:

"In traditional Hibernate you could map the collection as Bag,

which is just a regular Collection with no ordering or uniqueness guarantees"

How Can I map this collection with no ordering or uniqueness with annotation? Thanks.

like image 937
raonirenosto Avatar asked Jan 15 '23 09:01

raonirenosto


1 Answers

If you use a List as the reference type but do not specify an index number column, you will have an unordered collection with no uniqueness requirement. Yes the list is an ordered collection at the java level, but there is no guarantee across copies of the entity that they have the same order.

@OneToMany
private List<OtherEntity> otherEntities;

That's all!

like image 144
Affe Avatar answered Jan 17 '23 04:01

Affe