Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

composite-id hibernate problem

 
g patton
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

 
Jaikiran Pai
Marshal
Pie
Posts: 10447
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic