P.S.
P.S.

Reputation: 647

Mapping bag and set using JPA annotations

I am trying to migrate hibernate XML files to JPA annotations. I need to map and collections in JPA. Currently, i am using one-to-many, many-to-one collections annotations, but i cant find attributes that will distinguish between the different collections. Any suggestions on this?

Upvotes: 1

Views: 2047

Answers (1)

frm
frm

Reputation: 3486

You can't specify the concrete implementation of collections used by your JPA implementations. You have to use the usual Collections interfaces (Set, List, etc.): your persistence provider will implement these interfaces and set the properties of your entities as needed.

One big problem (and the default strategy) with OneToMany relations is lazy loading. The persistence provider will implement the Collection interfaces so that it can dinamically load related entities when the elements in the collection are first accessed. This is why you can't specify a concrete implementation of a collection: the one used by your JPA provider usually is a "special implementation".

Upvotes: 2

Related Questions