-->
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.  [ 6 posts ] 
Author Message
 Post subject: hib query returns null when the record IS in db
PostPosted: Fri Jul 15, 2005 6:26 am 
Newbie

Joined: Fri Jul 08, 2005 4:40 am
Posts: 8
hib query returns null when the record IS in db:


Mapping document:

<hibernate-mapping>

<class name="fuckthegest.model.Magazzino" table="LOY_MAGAZZINO">

<composite-id>
<key-property name="cmp" type="string" column="C_CMP" />
<key-property name="codArt" type="string" column="C_COD_ART" />
<key-property name="pntVen" type="string" column="C_PNT_VEN" />
</composite-id>

<property name="qtaLim" type="int" column="N_QTA_LIM" />

<property name="qtaRif" type="int" column="N_QTA_RIF" />

</class>

<query name="fuckthegest.model.findMagazzino">
<![CDATA[
from fuckthegest.model.Magazzino as mag
where mag.cmp = :cmp
and mag.codArt = :codArt
and mag.pntVen = :pntVen
]]>
</query>

</hibernate-mapping>

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

Query query = session.getNamedQuery("fuckthegest.model.findMagazzino");

query.setString("cmp", cmp);
query.setString("codArt", art);
query.setString("pntVen", pntVen);


Magazzino magazzino = (Magazzino)query.uniqueResult();

at this poin magazzino is null, but if i execute the hib generated query i find the record
i mean the record is present in the db but query.uniqueResult() returns null !!


Name and version of the database you are using:
oracle

The generated SQL (show_sql=true):

select magazzino0_.C_CMP as C_CMP,
magazzino0_.C_COD_ART as C_COD_ART,
magazzino0_.C_PNT_VEN as C_PNT_VEN,
magazzino0_.N_QTA_LIM as N_QTA_LIM,
magazzino0_.N_QTA_RIF as N_QTA_RIF
from LOY_MAGAZZINO magazzino0_
where (magazzino0_.C_CMP=? )and(magazzino0_.C_COD_ART=? )and(magazzino0_.C_PNT_VEN=? )

i substitued ? with the actual values, executed the query and found the record .. now ... how is that possible


many thanx .. :D


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 15, 2005 7:30 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Since keys are Strings, check out how is it with truncation at runtime (when query actually gets executed).


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 15, 2005 7:45 am 
Newbie

Joined: Fri Jul 08, 2005 4:40 am
Posts: 8
thanx alesj for the help,

i tried substituting param values with actual strings but the result is the same .. a null obj!!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 15, 2005 7:54 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
This is a basic functionality.
Are you connecting to the right db?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 17, 2005 6:37 am 
Newbie

Joined: Fri Jul 08, 2005 4:40 am
Posts: 8
yes, im connecting to the right db

i do the same thing (retrieving an obj from db) in another part of may app, it's a different table/obj but i do it exactly the same way so i expected it to work fine .. mmm .. there's something strange going on ..

the strange thing is that the query hib creates is correct, i run it in my oracle client program and get the record i want ..

now i cant do any tests but tomorrow ill try to figure it out once again ..

thanx :P


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 18, 2005 10:54 am 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
This may seem like a weird question but for the record in question is ANY part of the composite primary key NULL?

Hibernate will return NULL if any part of your key is NULL. We had a view with a terrible Primary Key that caused us grief when we upgraded one time.


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