-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Help with createSQLQuery
PostPosted: Sun Jun 18, 2006 9:53 pm 
Newbie

Joined: Sun Jun 18, 2006 9:47 pm
Posts: 6
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.0

Mapping documents:

Code between sessionFactory.openSession() and session.close():
session = (sessionFactory != null) ? sessionFactory.openSession(): null threadLocal.set(session)

Full stack trace of any exception that occurs:
n" java.lang.ClassCastException: [Ljava.lang.Object;
at tempgeniusDAO.FdmSQL.queryDB(FdmSQL.java:51)
at tempgeniusDAO.FdmSQL.main(FdmSQL.java:25)

Name and version of the database you are using:
MS SQl Server 2000
The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:




I have this code that runs properly

String d="select HistAt as HistAt,RId as RId from tblrecord";
SQLQuery q=session.createSQLQuery(d);
q.addScalar("HistAt",Hibernate.STRING);
q.addScalar("RId",Hibernate.STRING);
List results=q.list();int i=0;

while (i<results.size()){

///What Can I put here to print the value of the query considering it is returning two values HistAt and RId
}


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 19, 2006 12:00 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
The thing returned from a query (whether SQL or HQL) that has more than one resulting value/entity is an array of Object large enough to hold all resulting values/entities. So in this case, you'll get an Object[2].

It is possible to discover this by doing this:
Code:
while (i<results.size()){
  Object unknown = results.get(i);
  System.out.println("Got: " + unknown); // Put breakpoint here and inspect unknown with your debugger.
}
Or, of course, you could come to the forum and ask :)

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.