-->
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: query results
PostPosted: Sat Aug 21, 2004 1:02 pm 
Newbie

Joined: Wed Jul 28, 2004 11:16 am
Posts: 6
Location: Australian in Ireland
Hi,

Is it possible to get back the attribute names in a query result

<query name="Cat,name" >
select cat.name, cat.weight from Cat as cat
where cat.weight > :weight
</query>

Code:
Query query = getQuery(params);
Iterator results = query.iterate();
while (results.hasNext()) {
  Object[] object = (Object[])results.next();
  for (int i=0; i < object.length; i++) {

   ....
  }
}



In the body of the for loop i can get the value
Code:
object[i]
and its type
Code:
query.getReturnTypes()[i].getReturnedClass()
but can i get back which attribute or column each value comesfrom?


thanks
Simon




Hibernate version:2.1.4

Mapping documents:Cat

Code between sessionFactory.openSession() and session.close():as above

Full stack trace of any exception that occurs:na

Name and version of the database you are using:MySql 4.1.2 alpha

Debug level Hibernate log excerpt:na


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 22, 2004 1:11 pm 
Regular
Regular

Joined: Mon Feb 23, 2004 10:42 pm
Posts: 102
Location: Washington DC
Take a look at Interceptor.onLoad().

Code:
/**
* Called just before an object is initialized. The interceptor may change the <tt>state</tt>, which will
* be propagated to the persistent object. Note that when this method is called, <tt>entity</tt> will be
* an empty uninitialized instance of the class.
*
* @return <tt>true</tt> if the user modified the <tt>state</tt> in any way.
*/
public boolean onLoad(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) throws CallbackException;

_________________
Matt Veitas


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.