Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #14348

Re: Help with JTable ... ClassCastException

Path csiph.com!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail
From Lew <noone@lewscanon.com>
Newsgroups comp.lang.java.programmer
Subject Re: Help with JTable ... ClassCastException
Date Sun, 06 May 2012 20:43:48 -0700
Organization albasani.net
Lines 53
Message-ID <jo7gdm$pu2$1@news.albasani.net> (permalink)
References <4fa64c84$0$1377$4fafbaef@reader2.news.tin.it>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Trace news.albasani.net wHgwsOcm/uglrdPyHpfTpI1MPlvsGffxIakmizc6/ce8vSniBLDXbvnMSrVfD4BcULFQxZqtPerASpbIXpZ0qYFHxsooXPqq/kw9uP4ICHAhOHrVYSciPcl8shVmNx4E
NNTP-Posting-Date Mon, 7 May 2012 03:43:50 +0000 (UTC)
Injection-Info news.albasani.net; logging-data="SBwDz3fa0FmIPT0oFCuWOi26VqHurdm0x0dfZsbUX0SmdrIbXeLJL8gPMDXedSEFqvomIJRS1u9I9YB/6ptUXMLR/+5FexCUH7zygrFy3rTWJMKL9jZT3fvTWOJfHiE4"; mail-complaints-to="abuse@albasani.net"
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120430 Thunderbird/12.0.1
In-Reply-To <4fa64c84$0$1377$4fafbaef@reader2.news.tin.it>
Cancel-Lock sha1:a5zklM6fSM9faHgNjvAenos6sbM=
Xref csiph.com comp.lang.java.programmer:14348

Show key headers only | View raw


On 05/06/2012 03:03 AM, Luiss wrote:
> Hi all,
>
> I'm writing a GUI to show a JTable cointaining data from a db table (after
> I'll add also buttons to Add, Update and Delete rows). I need to have
> different table fields and not only strings.
>
> I've used Hibernate to do the select and then passed the list to a Vector
> containing ConfigPersonale objects (my table bean).
>
> I get this exception running the GUI:
>
> ********************************
> Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException:
> com.ale.ts.persistence.ConfigPersonale cannot be cast to java.util.Vector

Don't use 'Vector' anyway, and do perform all GUI work on the Event Dispatch 
Thread.

In this code:

> public class QueryConfigPersonale {
>     private Session session;
>     private Query query;
>     private List<ConfigPersonale> configPersList;
>
>     //select * from ConfigPersonale
>     @SuppressWarnings("unchecked")
>     public Vector<ConfigPersonale> getConfigPersonale() {
>         session = SessionFactoryUtil.getSessionFactory().getCurrentSession();
>         session.beginTransaction();
>         query = session.createQuery("from ConfigPersonale");
>
>         configPersList = query.list();
>         session.getTransaction().commit();
>
>         return new Vector<ConfigPersonale>(configPersList);
>     }
> }

you use old-fashioned Hibernate ('Session' instead of 'EntityManager'). Use 
the JPA style.

Don't suppress unchecked warnings. That's very bad. How do you know it's safe 
to do that? You have absolutely no documentation in your code to explain why 
it's safe. That's bad.

The Hibernate query returns a list already. Why convert it to a 'Vector'?

-- 
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Help with JTable ... ClassCastException Luiss <luiss@aol.com> - 2012-05-06 12:03 +0200
  Re: Help with JTable ... ClassCastException Luiss <luiss@aol.com> - 2012-05-07 00:18 +0200
  Re: Help with JTable ... ClassCastException Roedy Green <see_website@mindprod.com.invalid> - 2012-05-06 19:14 -0700
  Re: Help with JTable ... ClassCastException Lew <noone@lewscanon.com> - 2012-05-06 20:43 -0700

csiph-web