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: Why does createQuery(hqlQuery).list() return Object[]??
PostPosted: Thu May 22, 2008 3:17 pm 
Newbie

Joined: Fri Apr 04, 2008 2:12 pm
Posts: 11
Hibernate version:
hibernate-3.2.5

Mapping documents:
<hibernate-mapping>
<class name="de.laliluna.example.Honey" table="honey">
<id name="id" column="id" type="long">
<generator class="increment"/>
</id>
<property name="name" column="name" type="java.lang.String" />
<property name="taste" column="taste" type="java.lang.String" />
</class>
</hibernate-mapping>
taken from http://www.roseindia.net/hibernate/index.shtml

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

private int selectHoney(String query, String comment, boolean order)
{
Transaction dutTx = null;

InitSessionFactory dutInit = new InitSessionFactory();
Session dutSession = dutInit.getDutInstance().getCurrentSession();

List dutRecords = null;

try
{
dutTx = dutSession.beginTransaction();
dutRecords
= dutSession.createQuery(query).list();

dutTx.commit();
dutInit.closeDut();

Full stack trace of any exception that occurs:

Name and version of the database you are using:

mysql 5.0.45 with JDBC 3.1.14

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Hi,

I am wondering if I doing this wrong, but I am wondering why createQuery(someHQLQuery).list() returns an Object[] and not a Object? This will really make my java reflections code messier. Is there another solution? I rather have HQL return a Honey Object, so I can get information from all the columns. Currently, the Object[] does not include the auto_increment 'id' column. Thank you for any help you can provide.

Thanx,

brad


Top
 Profile  
 
 Post subject: re:Why does createQuery(hqlQuery).list() return Object[]??
PostPosted: Thu May 22, 2008 3:29 pm 
Beginner
Beginner

Joined: Fri Jun 29, 2007 11:12 am
Posts: 25
Hello Brad,
it really depends on the query, for example:
Code:
...
from a, b
where ...


would return Object[] pair

for

Code:
...
from a
...


would get a list<a>.


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.