• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

composite-id hibernate problem

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am trying to execute a select query on a table that contains a composite id,
but I keep getting a java.lang.ClassCastException: java.lang.String exception.

Any suggestions ?

My Documents.hbm.xml



My Documents POJO


My DocuemntsId POJO



Mysql Database


Code to get query

 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by g patton:

String sqlQuery = "Select documents.documentsId.docNumber from Documents documents where documents.docclassNumber like '"+archive+"%'";
System.out.println(sqlQuery);
Query query = session.createQuery(sqlQuery);
tx.commit();
for (Iterator it = docNumbers.iterate(); it.hasNext(); ) {
Object[] row = (Object[])it.next(); ---- This line throws the error



documents.documentsId.docNumber in the select query is going to return you a String. So your code should look like:


[ June 21, 2007: Message edited by: Jaikiran Pai ]
 
g patton
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It works , thanks . Jaikiran Pai ROCKS !!

I've been stuck on this for ages and it seems embarrassingly obvious now.

I'm new to hibernate so I wouldn't beat myself up too much. Thanks again.
reply
    Bookmark Topic Watch Topic
  • New Topic