• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Joe Ess
  • salvin francis

composite-id hibernate problem

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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.
 
crispy bacon. crispy tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!