This is a fundamental java issue. You will never be able to cast a list to
a set because a list allows duplicates whereas a set dose not. There is no
way for java to know which of the duplicate elements it should use. If you
guarantee that you have unique result from your DB(i.e. use the unique
keyword), then you can programatically create a set from a list.
off the top of my head....
List<Product> products = (List<Product>)queryForList("Products.selectAll");
HashSet<Product> productsSet = new HashSet<Product>(products.size());
for(Product p:products) {
productsSet.add(p);
}
On Mon, Apr 6, 2009 at 10:53 PM, fer knjige <[email protected]> wrote:
> Unfortunately this doesn't work. It returns following error:
>
> Exception in thread "main" java.lang.ClassCastException:
> java.util.ArrayList.
>
> Solution?
>
> 2009/4/6 Larry Meadors <[email protected]>
>
> return new LinkedHashSet(queryForList(...));
>>
>> Larry
>>
>>
>> On Sun, Apr 5, 2009 at 10:53 PM, fer knjige <[email protected]> wrote:
>> > Hi,
>> >
>> > I have a simple query:
>> >
>> > select * from Products.
>> >
>> > I want to have results in Set not in List. How can I do it since
>> > method 'queryForList' returns only List?
>> >
>> > Thanks in advance!
>> >
>> >
>> >
>>
>
>