-->
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.  [ 3 posts ] 
Author Message
 Post subject: Query.list() intermittently returns null values in List
PostPosted: Sat Aug 05, 2006 3:25 am 
Newbie

Joined: Sat Aug 05, 2006 2:49 am
Posts: 3
I've fought posting this, since it seems like such a basic thing, but after 3 days of fighting with it, I'm not getting anywhere. Either my keywords trying to find a solution in the archives and via google are poor, or sleep deprivation is really taking it's toll.

We have a very basic Struts-based web application. I have a form that is used to construct an instance of our mapped object, which is then used to Query-By-Example. We want to display the results of the query in tabular form on a second page.

Looking at detailed hibernate logs, the query builds correctly, and appears to run and retrieve the correct rows. The problem occurs when we try to access the results in the list. I think this has to do with lazy initialization of the results, but am not sure how to remedy the situation.

Initially, we passed the List returned from the Query.list() method to the results page. On that page, we used the struts:logic taglib to iterate through the list. Depending on query criteria, the page would either work properly, or fail due to encountering a null inside the collection.

I tried to figure out how to set lazy initialization to false via XDoclet, but have come up empty. I added the following to the class-level @hibernate tag, but it did not seem to have any effect:

@hibernate.class table="MY_TABLE" lazy="false"

I thought I had read that objects would be initialzed from a list of references if list.get() was explicitly called for the object. I tried the code below after the query where I manually go through the list and call get(i) for each element in the set. When looking at the log output, I get a few, but not all the rows, with the majority returned as NULL. For example on a query that should return a max of 10,000 rows out of a result set of 10,018, the returned list shows size=10,000, but stepping through the list results in 438 objects, the rest of the elements return null. Looking at the logs, the hibernate extraction code indicates there are values for all of the rows, so I'm not sure why they don't make it into the collection. It almost looks like there is a timing issue since modifying the parameters sometimes allow the set to return properly, yet other times a query that just ran correctly will fail with null rows.

I tried switching to a StatelessSession object to see if that helped, but got the same result.

Is there any way for me to specify that all elements should be immediately constructed from the result set? Is there a different way I should be approaching this?

I'm sorry if this has been covered in depth already, but I'm not finding in in my searches (or in the Hibernate in Action book) and am running out of time on this. It seems to be a trivial example, so any help in getting me back on track is GREATLY appreciated.

Note: I also have a Native SQL query that shows the same behavior.

Hibernate version: 3.1.3

Mapping documents:

Class mapping files generated by XDoclet

[i]hibernate.cfg.xml[i]

<hibernate-configuration>
<session-factory>
<property name="connection.datasource">jdbc/myDS</property>
<mapping resource="foo/bar/MyObject.hbm.xml" />
</session-factory>
</hibernate-configuration>

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

Session session =
HibernateUtil.getSessionFactory().openSession();

Criteria criteria = session.createCriteria(MyObject.class);
criteria.add(
Example.create(quote).setPropertySelector(
new NonNullPropertySelector()));
criteria.add(
Expression.between(
"key.eventTimestamp",startTime,endTime));

criteria.setFirstResult(offset);
criteria.setMaxResults(size);
criteria.addOrder(Order.asc("key.eventTimestamp"));
List result = criteria.list();

List results =
QueryManager.queryByExample(
session,quote,startTime,endTime,offset,size);

for(int i=0; i<results.size(); i++) {
logger.debug("Row: "+results.get(i));
}

mmForm.setResultsSize(results.size());
req.setAttribute("MMQUOTE_RESULTS",results);

Full stack trace of any exception that occurs:

Name and version of the database you are using:
Oracle 10g


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 05, 2006 12:45 pm 
Newbie

Joined: Sat Aug 05, 2006 2:49 am
Posts: 3
One additional bit of information:

This entity makes use of a composite id. The mapping from class to table is straightforward, with each row of the table mapping to a single entity.

I think some of the problem might be due to the composite id, but don't really have another solution. This is legacy data, and makes use of a natural key.

This is a basic query-and-display function, and the rows will not be updated.

Can anyone offer any pointers?

Thanks.


Top
 Profile  
 
 Post subject: Query.list() returns null values in List
PostPosted: Tue Aug 07, 2007 8:07 am 
Newbie

Joined: Tue Aug 07, 2007 7:53 am
Posts: 1
We are using Oracle 9i, and hibernate 3.2.0.ga
all Query.list() calls returns a List with most of its elements as "null"

we are accessing a legacy Oracle database and have used Hibernate Reverse Engineering tool to generate the Mapping and the Entity Classes, since the legacy database does't have primary keys, only business keys, Hibernate has generated a composite-id class and used it in all the mapped entities.

our case is exactly like yours, please update us with any feedback you get.

and Forum Admin, Please give high priority to this issue, since it is very strange and not documentes anywhere else


Note:
we have had used the same Hibernate jar version with SQL server database and we never faced this issue


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.