• 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
Sheriff
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.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!