Does JPA ( Eclipselink in this case) always return IndirectList where Entity have a List? Is ok that list or It should be converted to another list( maybe linkedlist)?
2 Answers
Analysis
If we look at EclipseLink's IndirectList's API, it says:
To use an IndirectList: declare the appropriate instance variable with type IndirectList (jdk1.1) or Collection/List/Vector (jdk1.2).
TopLink will place an IndirectList in the instance variable when the containing domain object is read from the datatabase. With the first message sent to the IndirectList, the contents are fetched from the database and normal Collection/List/Vector behavior is resumed.
If we view IndirectList sources, we will see, that all the work is delegated to it's original collection, just like API says.
Answers
Does JPA ( Eclipselink in this case) always return IndirectList where Entity have a List?
Yes, it always does return your specified collection wrapped with IndirectList. Since it delegates all its internal work to the wrapped collection, it preserves the way it works.
Is ok that list or It should be converted to another list( maybe linkedlist)?
Yes, it is okay to use IndirectList. You don't convert, you just define any type of collection you want and don't worry about IndirectList, since it is managed transparently.

- 6,372
- 2
- 28
- 41
-
Nicer answer than mine to be honest. +1 – siebz0r Jun 11 '12 at 08:09
-
3Great answer. One addition is that EclpseLink will use indirectList or other IndirectContainer implementation when the collection is lazy loaded. Eagerly fetched relationships should use a java Collection implementation type by default. EclipseLink can be customized to use which ever collection implementation required when building your entities. – Chris Jun 11 '12 at 14:21
-
How we can customize which ever collection implementation required? – Pramil Sep 14 '17 at 15:04
Since List
is an interface the JPA provider is free to return any implementation. EclipseLink rerurns an IndirectList
where a List
is used. This is perfectly fine since the IndirectList
is a List
.
For the record or for future reference, it is generally best practice to use interfaces with JPA.

- 18,867
- 14
- 64
- 107
-
I spent some time searching through the JPA 2.1 spec for a word or two that comments on this explicitly, without no luck. Have you found a passage? – Martin Andersson Mar 24 '14 at 23:06
-
@MartinAndersson I am not a JPA user anymore, but I'll take a shot at it. I don't think this will be in the JPA spec, you'll have a better chance looking in the documentation of implementations (EclipseLink, Hibernate, etc.). `org.eclipse.persistence.indirection.IndirectList` is EclipseLink specific. – siebz0r Mar 25 '14 at 07:34
-
-