From users-return-1469-apmail-openjpa-users-archive=openjpa.apache.org@openjpa.apache.org Tue Jan 22 23:49:26 2008 Return-Path: Delivered-To: apmail-openjpa-users-archive@locus.apache.org Received: (qmail 25304 invoked from network); 22 Jan 2008 23:49:26 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 22 Jan 2008 23:49:26 -0000 Received: (qmail 47413 invoked by uid 500); 22 Jan 2008 23:49:16 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 47393 invoked by uid 500); 22 Jan 2008 23:49:16 -0000 Mailing-List: contact users-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@openjpa.apache.org Delivered-To: mailing list users@openjpa.apache.org Received: (qmail 47384 invoked by uid 99); 22 Jan 2008 23:49:16 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 22 Jan 2008 15:49:16 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [217.146.188.67] (HELO smtp807.mail.ird.yahoo.com) (217.146.188.67) by apache.org (qpsmtpd/0.29) with SMTP; Tue, 22 Jan 2008 23:48:48 +0000 Received: (qmail 13537 invoked from network); 22 Jan 2008 23:48:51 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=btinternet.com; h=Received:X-YMail-OSG:X-Yahoo-Newman-Property:Message-ID:Date:From:Reply-To:User-Agent:MIME-Version:To:Subject:References:In-Reply-To:Content-Type; b=4lEEGFIGlPfbBBQy96ngdz2DMpDWKtdRGl95RKGHuYwwdDeHfE/Rswf/y/FKAU8KwKzO8lQWmIjgt5Vjt7XZlKchVjQYLnIRigZ9xt7JDSXACHZnIqU8aF7p1J2jCCeAehaJstFEu+uGyCmEVInRk152UXmSIpNf+esR519pDD4= ; Received: from unknown (HELO ?192.168.1.67?) (david.m.beer@btinternet.com@86.133.179.239 with plain) by smtp807.mail.ird.yahoo.com with SMTP; 22 Jan 2008 23:48:51 -0000 X-YMail-OSG: qvd1z6gVM1leFFHbdUXKCkJ2t0XGzOVxq_mU4yE.2DFDrESTHvkKlRTSVOF9eCGQibZfkOZtYGhxIHK.a2T_hs39UW7Z3si8VfMtgbmdT5FFq9fh X-Yahoo-Newman-Property: ymail-3 Message-ID: <479680DD.9010803@btinternet.com> Date: Tue, 22 Jan 2008 23:48:45 +0000 From: David Beer Reply-To: david.m.beer@btinternet.com User-Agent: Thunderbird 2.0.0.6 (X11/20071022) MIME-Version: 1.0 To: users@openjpa.apache.org Subject: Re: Understanding getResultList() References: <914510.56096.qm@web86612.mail.ird.yahoo.com> <87C79F56-3E05-4EEF-8A9A-7D44D6DC9787@SUN.com> In-Reply-To: <87C79F56-3E05-4EEF-8A9A-7D44D6DC9787@SUN.com> Content-Type: multipart/mixed; boundary="------------000305080700050405090100" X-Virus-Checked: Checked by ClamAV on apache.org --------------000305080700050405090100 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi Guys The Entry class is actually an entity I just changed the code to use native query as I was getting the same result using just createQuery. I have attached the Entry.class and the class containing the query (EntryQuery). As you can see in EntryQuery there is various code commented out, this is just where I have tried different things. When I return the list of results and try and display them in a JList with the following code: data = eq.getAll(); jList1.setListData((Vector)data); I get the following exception: java.lang.ClassCastException: org.apache.openjpa.kernel.DelegatingResultList cannot be cast to java.util.Vector at veilig.mainui.VeiligTopComponent.(VeiligTopComponent.java:37) at veilig.mainui.VeiligTopComponent.getDefault(VeiligTopComponent.java:94) at veilig.mainui.VeiligTopComponent$ResolvableHelper.readResolve(VeiligTopComponent.java:149) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at java.io.ObjectStreamClass.invokeReadResolve(ObjectStreamClass.java:1061) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1762) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351) at org.netbeans.modules.settings.convertors.XMLSettingsSupport$SettingsRecognizer.readSerial(XMLSettingsSupport.java:542) at org.netbeans.modules.settings.convertors.XMLSettingsSupport$SettingsRecognizer.instanceCreate(XMLSettingsSupport.java:574) at org.netbeans.modules.settings.convertors.SerialDataConvertor$SettingsInstance.instanceCreate(SerialDataConvertor.java:415) [catch] at org.netbeans.core.windows.persistence.PersistenceManager.getTopComponentPersistentForID(PersistenceManager.java:513) at org.netbeans.core.windows.persistence.PersistenceManager.getTopComponentForID(PersistenceManager.java:618) at org.netbeans.core.windows.PersistenceHandler.getTopComponentForID(PersistenceHandler.java:422) at org.netbeans.core.windows.PersistenceHandler.load(PersistenceHandler.java:147) at org.netbeans.core.windows.WindowSystemImpl.load(WindowSystemImpl.java:69) at org.netbeans.core.NonGui$3.run(NonGui.java:205) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209) at java.awt.EventQueue.dispatchEvent(EventQueue.java:597) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160) at java.awt.EventDispatchThread.run(EventDispatchThread.java:121) Any help or guidance is very much appreciated. David Craig L Russell wrote: > Hi David, > > One other thing that occurs to me is whether you're using the native > query appropriately. > > I assume that Entry.class is *not* an Entity. It's just a plain old > Java class with no persistence annotations. > > Perhaps we can help better if you would include your Entity.java and > schema in the message. And the exception with stack trace. > > Regards, > > Craig > > On Jan 22, 2008, at 2:55 AM, David Beer wrote: > >> Hi Patrick >> >> I will be able to get the exact information retruned later when I am >> back home. >> >> I am trying to display a list of the items returned from the query in >> a JList (javax.swing.JList). A JList takes either an array, a >> ListModel or a Vector; I was trying to use a Vectory as I can just >> add elements to it and not worry about memory allocation or the size >> of the Vector being too large. >> >> My point is that when I tried to cast the resulting data from the >> query I got an exception. Cannot Cast Delegate org.apache.openjpa >> >> I will get the exact data this evening when i get home >> >> Thanks >> >> David >> >> ----- Original Message ---- >> From: Patrick Linskey >> To: users@openjpa.apache.org; david.m.beer@btinternet.com >> Sent: Monday, 21 January, 2008 11:52:15 PM >> Subject: Re: Understanding getResultList() >> >> 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 >> 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 results = >> (List)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 >> >> >> >> > > 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! > --------------000305080700050405090100 Content-Type: text/x-java; name="EntryQuery.java" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="EntryQuery.java" /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package veilig.db.query; import java.util.List; import java.util.List; import java.util.Vector; import java.util.logging.Level; import java.util.logging.Logger; import javax.persistence.EntityManager; import javax.persistence.EntityTransaction; import javax.persistence.Query; import veilig.entry.Entry; import veilig.entry.Entry; import veilig.util.db.DatabaseConnection; /** * * @author david */ @SuppressWarnings("static-access") public class EntryQuery { private static final DatabaseConnection dbconn = DatabaseConnection.getInstance(); private static EntryQuery instance = null; public EntryQuery() { } public static EntryQuery getInstance() { if (instance == null) { instance = new EntryQuery(); } return instance; } public List getAll() { //List results = null; EntityManager manager = dbconn.getEm(); EntityTransaction tx = manager.getTransaction(); tx.begin(); try { System.out.println("about to run query"); Query query = manager.createNativeQuery("SELECT * FROM ENTRY", Entry.class); //Query query = manager.createQuery("SELECT a FROM Entry a"); List results = (List)query.getResultList(); /*Vector data = new Vector(0, 1); for (Entry entry : results) { System.out.println("Name " + entry.getName()); /*Entry e = new Entry(); e.setId(entry.getId()); e.setEmail(entry.getEmail()); e.setName(entry.getName()); e.setPassword(entry.getPassword()); e.setUrl(entry.getUrl()); e.setUsername(entry.getUsername()); data.add(e); Entry e = entry; data.add(e); }*/ tx.commit(); return results; } catch (Exception exception) { Logger.getLogger(EntryQuery.class.getName()).log(Level.SEVERE, "Problem getting list of entries from databse", exception); tx.rollback(); return null; } } } --------------000305080700050405090100 Content-Type: text/x-java; name="Entry.java" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="Entry.java" package veilig.entry; import java.net.URL; import java.util.List; import java.util.Vector; import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.OneToMany; import javax.persistence.OneToOne; @Entity public class Entry implements java.io.Serializable { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) private Integer id; private String name; private String username; private String email; //private URL url; private String url; private char[] password; @OneToMany(cascade=CascadeType.ALL) private List addInfo; /** * Constructor */ public Entry() { } /** * * @return id for this item */ public Integer getId() { return id; } /** * Sets the id * @param id to be used */ public void setId(Integer id) { this.id = id; } /** * Name * @return the name of the entry */ public String getName() { return name; } /** * Sets the name of the Entry * @param name to be used */ public void setName(String name) { this.name = name; } /** * Username related to the entry * @return username */ public String getUsername() { return username; } /** * Username related to the entry * @param username to be used */ public void setUsername(String username) { this.username = username; } /** * The email address associated with this entry * @return email address */ public String getEmail() { return email; } /** * Sets the email address for this Entry * @param email address for this entry */ public void setEmail(String email) { this.email = email; } /** * The url or web address for this Entry * @return url - web address */ public String getUrl() { return url; } /** * Sets the url - web address for this Entry * @param url - web address */ public void setUrl(String url) { this.url = url; } /** * A list of any additional information about the entry * @return a List containing one or many addition information objects */ public List getAddInfo() { return addInfo; } /** * Adds a List of AdditionalInformation Objects * @param ai Ovewrites the current list with the new one */ public void setAddInfo(List ai) { this.addInfo = ai; } /** * Adds an object of AdditionalInformation to the list. * @param ai Additionalinformation object to be added */ public void addAdditInfo(AdditionalInformation ai) { if(addInfo == null) addInfo = new Vector(0,1); addInfo.add(ai); } public char[] getPassword() { return password; } public void setPassword(char[] password) { this.password = password; } @Override public String toString() { return this.name; } } --------------000305080700050405090100--