• 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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.
 
You got style baby! More than this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic