Search by ID java.lang.ClassCastException

View: New views
5 Messages — Rating Filter:   Alert me  

Search by ID java.lang.ClassCastException

by ghachey :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I have been experiencing a problem for a while.  I use:

trails-1.2.2-SNAPSHOT

$ java -version
java version "1.5.0_16"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b02)
Java HotSpot(TM) 64-Bit Server VM (build 1.5.0_16-b02, mixed mode)

tomcat5.5 (5.5.26-5) (I also test with tomcat:run and jetty:run from maven)

I have an object model called Complaint.java.  It uses an id of type Long for the primary key.  The whole application works fine except when I try to search for a complaint using the id field I get a java.lang.ClassCastException runtime exception (tapestry error Screenshot.png).  Searching with id works fine for all other objects.

I get the same problem with both hsql and postgresql databases.

A simple test case ComplaintTest.java fails to build with postgresql with this message and fails to build with hsql with this one.

I remember several weeks ago trying to test with an id of type Integer but getting the same error.

Here is what the hibernate generated DB schema for this object looks like.

Any ideas?

--
GH

RE: Search by ID java.lang.ClassCastException

by nhhockeyplayer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hey Ghach...
 
At first glance I would refrain from using EqualsBuilder.reflectionEquals(this, obj);
 within your equals method. Don't recall but a bit back I ran into a problem operating that.
 
Also, might want to try setting your id to null instead of 1L... just to try and shake it out. Shouldn't really have to set it to anything, although someone picky will shout up some best practice, it don't really matter.
 
I used Integer for my ID's within the roster demo. And I highly suggest you refer to the same demo for canonical usage of ID's, equals and hashcode for your domain objects.
 
So how have you been able to get by without any OneToOne support within your domain?
 
- cheers

Best regards
Ken in nashua




 

> Date: Fri, 6 Mar 2009 21:10:08 -0800
> From: ghachey@...
> To: users@...
> Subject: [trails-users] Search by ID java.lang.ClassCastException
>
>
> Hi,
>
> I have been experiencing a problem for a while. I use:
>
> trails-1.2.2-SNAPSHOT
>
> $ java -version
> java version "1.5.0_16"
> Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b02)
> Java HotSpot(TM) 64-Bit Server VM (build 1.5.0_16-b02, mixed mode)
>
> tomcat5.5 (5.5.26-5) (I also test with tomcat:run and jetty:run from maven)
>
> I have an object model called
> http://www.nabble.com/file/p22384565/Complaint.java Complaint.java . It
> uses an id of type Long for the primary key. The whole application works
> fine except when I try to search for a complaint using the id field I get a
> java.lang.ClassCastException runtime exception (tapestry error
> http://www.nabble.com/file/p22384565/Screenshot.png Screenshot.png ).
> Searching with id works fine for all other objects.
>
> I get the same problem with both hsql and postgresql databases.
>
> A simple test case http://www.nabble.com/file/p22384565/ComplaintTest.java
> ComplaintTest.java fails to build with postgresql with
> http://www.nabble.com/file/p22384565/vu.org.ombudsman.ComplaintTest.txt_psql
> this message and fails to build with hsql with
> http://www.nabble.com/file/p22384565/vu.org.ombudsman.ComplaintTest.txt this
> one .
>
> I remember several weeks ago trying to test with an id of type Integer but
> getting the same error.
>
> Here is what the hibernate
> http://www.nabble.com/file/p22384565/complaint.sql generated DB schema for
> this object looks like.
>
> Any ideas?
>
> --
> GH
> --
> View this message in context: http://www.nabble.com/Search-by-ID-java.lang.ClassCastException-tp22384565p22384565.html
> Sent from the Trails - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
> http://xircles.codehaus.org/manage_email
>
>


HotmailĀ® is up to 70% faster. Now good news travels really fast. Find out more.
Best regards
Ken in nashua

RE: Search by ID java.lang.ClassCastException

by ghachey :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hey Ken,

>At first glance I would refrain from using EqualsBuilder.reflectionEquals(this, obj);
> within your equals method. Don't recall but a bit back I ran into a problem operating that.

Yeah I usually don't use it.  I just tried this once.

>Also, might want to try setting your id to null instead of 1L... just to try and shake it out. Shouldn't really have to set it to >anything, although someone picky will shout up some best practice, it don't really matter.

I had tried that but did not make any difference.

>I used Integer for my ID's within the roster demo. And I highly suggest you refer to the same demo for canonical usage >of ID's, equals and hashcode for your domain objects.

The only reason I went with Long was that this project is a port of an existing database and for some reason they have insanely huge IDs.  However, it'll be a while before it reaches the Integer limit so I went back to using Integer.  I don't get the error message anymore so thats good but still don't have an understanding of the problem I had unfortunately.  Ha well...

Thanks,

--
GH

RE: Search by ID java.lang.ClassCastException

by nhhockeyplayer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hey Ghach... cool glad you resolved it.
 
Still curious if I am the only guy on the planet that uses OneToOne in trails. If your domain model matures I'd sure like to know if trails delivers for you in this regard.

Best regards
Ken in nashua




 

> Date: Sun, 8 Mar 2009 16:11:02 -0700
> From: ghachey@...
> To: users@...
> Subject: RE: [trails-users] Search by ID java.lang.ClassCastException
>
>
> Hey Ken,
>
> >At first glance I would refrain from using
> EqualsBuilder.reflectionEquals(this, obj);
> > within your equals method. Don't recall but a bit back I ran into a
> > problem operating that.
>
> Yeah I usually don't use it. I just tried this once.
>
> >Also, might want to try setting your id to null instead of 1L... just to
> try and shake it out. Shouldn't really have to set it to >anything, although
> someone picky will shout up some best practice, it don't really matter.
>
> I had tried that but did not make any difference.
>
> >I used Integer for my ID's within the roster demo. And I highly suggest you
> refer to the same demo for canonical usage >of ID's, equals and hashcode for
> your domain objects.
>
> The only reason I went with Long was that this project is a port of an
> existing database and for some reason they have insanely huge IDs. However,
> it'll be a while before it reaches the Integer limit so I went back to using
> Integer. I don't get the error message anymore so thats good but still
> don't have an understanding of the problem I had unfortunately. Ha well...
>
> Thanks,
>
> --
> GH
> --
> View this message in context: http://www.nabble.com/Search-by-ID-java.lang.ClassCastException-tp22384565p22404287.html
> Sent from the Trails - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
> http://xircles.codehaus.org/manage_email
>
>


Windows Liveā„¢: Keep your life in sync. Check it out.
Best regards
Ken in nashua

RE: Search by ID java.lang.ClassCastException

by ghachey :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>Still curious if I am the only guy on the planet that uses OneToOne in trails. If your domain model matures I'd sure like to >know if trails delivers for you in this regard.

No you are not.  I use it too :)  I just did not used it in this particular very small and simple project.

Regards,

--
GH