-->
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: Help with select
PostPosted: Tue Mar 08, 2016 7:00 am 
Newbie

Joined: Tue Jun 23, 2015 8:04 am
Posts: 2
Hi, guys...

I've very few experience with hibernate. Would like a help for this query:
Code:
   Query query = session.createSQLQuery("select numdn,dtentregacor,codentidade from dn      A,blocodn B"+
   " where A.numblocodn=B.numblocodn and A.dtentregacor!= :dtentregacor and"+
   " A.dtrecebcor= :dtrecebcor and A.numblocodn in(select numblocodn from blocodn"+
   " where B.codentidade='"+hospit[i]+"')");
   query.setParameter("dtentregacor","1000-01-01");
   query.setParameter("dtrecebcor","1000-01-01");
   String registro = query.uniqueResult().toString();
   

I'm getting NullPointerException in the line that contains the object registro.
What's wrong ?


Top
 Profile  
 
 Post subject: Re: Help with select
PostPosted: Tue Mar 08, 2016 8:35 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
There are many issues with your query:

1. SQL injection vulnerability because you concatenate parameters: hospit[i]. Maybe hospit is null here?
2. You select 3 columns and the result is an Object[] but you use toSting to capture the result?

A NullPointerException is best resolved during debugging since you need to know the state of every object.


Top
 Profile  
 
 Post subject: Re: Help with select
PostPosted: Tue Mar 08, 2016 9:13 am 
Newbie

Joined: Tue Jun 23, 2015 8:04 am
Posts: 2
Ok, thanks for the answer.
So, according with your reply:
1 - hospit[i] here is valid for index 0;
2 - I'm trying to get the result of the query in an array with 3 positions.


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.