-->
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: Using Native SQL with Join .Getting null pointer exception
PostPosted: Fri Feb 24, 2006 4:50 am 
Beginner
Beginner

Joined: Fri Nov 18, 2005 5:49 am
Posts: 23
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

Mapping documents:

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

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


I am using Hibernate 3.0 with SQL Server 2000 as back end.

I am using native SQL with join. The query is getting executed properly.
But when I try to retrieve the results using object[] , I am getting reference of the first table and a null reference of the second table.

I am furnishing the code below for ur reference.


public List findItemsToProcess(String status,String scheduledDate) throws EnfsApplicationException {
try {
String query = "select {I.*},{F.*} from dbo.ItemstoProcess I,FileReceivedSentLog F " +
"where I.FileRecievedSentId *= F.Id and " +
"((I.ScheduledDate >= ?) or (I.Status = ?)) and " +
"(I.ScheduledDate <= ?)" ;
Session session = getSession();
SQLQuery sqlQuery = session.createSQLQuery(query);
sqlQuery.addEntity("I",ItemsToProcess.class);
sqlQuery.addEntity("F",FileReceivedSentLog.class);
sqlQuery.setString(0,scheduledDate);
sqlQuery.setString(1,status);
sqlQuery.setString(2,scheduledDate);
return sqlQuery.list();

}
catch(HibernateException e) {
throw new EnfsApplicationException(e);
}


// ****** Test Case ********

List result = itemsToProcess.findItemsToProcess("P","1/1/2005");
Iterator i = result.iterator();
while(i.hasNext()) {
Object[]pair = (Object[])i.next();
System.out.println("Pair Length : " + pair.length);
System.out.println("Pair 0 : " + pair[0].toString());
System.out.println("Pair 0 : " + pair[1].toString());
}

First SOP return class name of ItemsToProcess
Second SOP doest not return class name of FileReceivedSentLog , Instead it returns null.



Matter is urgent. Pl help

Regards

Seshadri


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 24, 2006 8:12 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
and you are sure the resulting resultset does not contain nulls ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 24, 2006 9:39 am 
Beginner
Beginner

Joined: Fri Nov 18, 2005 5:49 am
Posts: 23
Thank you very much for ur quick response. In fact your statment opened my eyes.

In fact my example query with join , resultset contained Nulls in the joined table

Then I again executed another query with join , resultset containing both null and non null in the joined table.

I gave SOP for the non null rows which it printed.


So ur response really helped me. In case if i have any problems I will get back to you.

Regards

Seshadri


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.