Oleksii
Oleksii

Reputation: 154

EJB 2.1 Entity how to get List not Collection?

I'm using ejb 2.1 BMP, JBoss 7.1 AS
I need to get List ordered by some field(it depends on user choice)
from database using ORDER BY in SQL statement.
Home Interface:

public interface AliveHome {  
    ...  
    Collection<Alive> findAllConstraint(...) [exceptions];  
    ...
}

When i change return type to List i get exception:

java.lang.ClassCastException: java.util.HashSet cannot be cast to java.util.List $Proxy13.findAllConstraint(Unknown Source)

But i need List (because with HashSet there is no sense in ORDER BY)
How to get List?

Upvotes: 0

Views: 311

Answers (3)

barsju
barsju

Reputation: 4446

Have you tried using a LinkedHashSet? I think that works in EJB3 at least.

Upvotes: 0

Oleksii
Oleksii

Reputation: 154

There is no solution for JBoss 7. I just install JBoss 6
and it works with return type List ! =)

Upvotes: 0

TrueDub
TrueDub

Reputation: 5070

A hashset is unordered, so you can't get an ordered list from it automatically. You need to iterate over the hashset, adding the items to a list, then order that list as you require.

Upvotes: 1

Related Questions