You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by David Beer <da...@btinternet.com> on 2008/01/22 00:34:12 UTC

Understanding getResultList()

Hi All

I have a n issue with using Query getResultList(), I am executing a 
nativeQuery("SELECT * FROM ENTRY", Entry.class). And performing the 
query like so List<Entry> results = (List<Entry>)query.getResultList(); 
and in return I am seeing a list containing a delegate and a  
persistence object.

My main problem is that I am trying to display the resulting data that 
comes back in a JList, in order to set the list data on a JList you have 
to have the data in a Vector. So when I tried to cast the  List to a 
Vector I got an exception.

When I perform the same query using TopLink I get back a list of Objects 
of the type and no extra information. At the moment I am going through 
the results and getting each Object element and adding to Vector to 
display. This is fine with a small amount of records but what about a 
large amount of records.

What is the best way of getting back just a list of Objects no 
additional data?

Thanks

David

Re: Understanding getResultList()

Posted by Craig L Russell <Cr...@Sun.COM>.
Hi David,

On Jan 21, 2008, at 3:34 PM, David Beer wrote:

> Hi All
>
> I have a n issue with using Query getResultList(), I am executing a  
> nativeQuery("SELECT * FROM ENTRY", Entry.class). And performing the  
> query like so List<Entry> results =  
> (List<Entry>)query.getResultList(); and in return I am seeing a list  
> containing a delegate and a  persistence object.
>
> My main problem is that I am trying to display the resulting data  
> that comes back in a JList, in order to set the list data on a JList  
> you have to have the data in a Vector. So when I tried to cast the   
> List to a Vector I got an exception.

You might be better off creating a trivial implementation of a  
ListModel instead of using Vector (which is so last year).

JList(ListModel dataModel)
           Constructs a JList that displays elements from the  
specified, non-null, model.

Since there is no change possible to the underlying List, you just  
need to implement the getElementAt method and delegate to the  
underlying List.

Object getElementAt(int index)
           Returns the value at the specified index.

JList myJList = new JList( new MyListModel (listReturnedFromQuery));

class MyListModel{
List myList;
MyListModel(List underlying) {myList = underlying;}
void addListDataListener(ListDataListener l)  {throw  
NotImplementedException;}
void removeListDataListener(ListDataListener l)  {throw  
NotImplementedException;}
Object getElementAt(int index) {return myList.get(index);}
int getSize() {return myList.size();}
}

Craig
>
>
> When I perform the same query using TopLink I get back a list of  
> Objects of the type and no extra information. At the moment I am  
> going through the results and getting each Object element and adding  
> to Vector to display. This is fine with a small amount of records  
> but what about a large amount of records.

Creating your own ListModel will also address this issue.

Craig
>
>
> What is the best way of getting back just a list of Objects no  
> additional data?
>
> Thanks
>
> David

Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!


Re: Understanding getResultList()

Posted by Patrick Linskey <pl...@gmail.com>.
Hi,

> and in return I am seeing a list containing a delegate and a
> persistence object.

Can you include a printout of the data you see, or some more detailed
explanation, such as class names of the instances returned?

> display. This is fine with a small amount of records but what about a
> large amount of records.

Are you concerned about the overhead involved in iterating through a
result list fully just to copy it over to the Vector? If the framework
that you are using does not provide any interface-based support, then
you might not have many options. One idea might be to try to create a
subclass of Vector that overrides most methods to just return values
from the actual backing list.

-Patrick

On Jan 21, 2008 3:34 PM, David Beer <da...@btinternet.com> wrote:
> Hi All
>
> I have a n issue with using Query getResultList(), I am executing a
> nativeQuery("SELECT * FROM ENTRY", Entry.class). And performing the
> query like so List<Entry> results = (List<Entry>)query.getResultList();
> and in return I am seeing a list containing a delegate and a
> persistence object.
>
> My main problem is that I am trying to display the resulting data that
> comes back in a JList, in order to set the list data on a JList you have
> to have the data in a Vector. So when I tried to cast the  List to a
> Vector I got an exception.
>
> When I perform the same query using TopLink I get back a list of Objects
> of the type and no extra information. At the moment I am going through
> the results and getting each Object element and adding to Vector to
> display. This is fine with a small amount of records but what about a
> large amount of records.
>
> What is the best way of getting back just a list of Objects no
> additional data?
>
> Thanks
>
> David
>



-- 
Patrick Linskey
202 669 5907