-->
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.  [ 9 posts ] 
Author Message
 Post subject: Count(1) via getNamedQuery
PostPosted: Wed Apr 27, 2005 2:16 pm 
Newbie

Joined: Wed Apr 27, 2005 2:11 pm
Posts: 4
I was wondering how to do a standard count and call it via the getNamedQuery

Here is what i want to do
<sql-query name="verifyBetc"><![CDATA[select count(1) from tableName where item1 = 'IOGINC' and item1= 'C' and estab_dt < sysdate
and sysdate <= NVL(dslv_dt, sysdate)]]></sql-query>

Will this work above or do i need to map a return in there. Also what is the code i use to call get the value of the count?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 27, 2005 2:49 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
look in the docs for how you map it - you need to map the return (s).


the same goes for how to call it - its in the docs.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 27, 2005 2:53 pm 
Newbie

Joined: Wed Apr 27, 2005 2:11 pm
Posts: 4
I see how to map to custom object but i dont wanna do that. All i am returning is a number. I looked through the docs and found nothing. I searched through this forumand found not thing about returing the count via a getNamedQuery call. Please help a little more


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 27, 2005 3:03 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Please read the docs!

From http://www.hibernate.org/hib_docs/v3/re ... medqueries

A named SQL query may return a scalar value. You must specfy the column alias and Hibernate type using the <return-scalar> element:

<sql-query name="mySqlQuery">
<return-scalar column="name" type="string"/>
<return-scalar column="age" type="long"/>
SELECT p.NAME AS name,
p.AGE AS age,
FROM PERSON p WHERE p.NAME LIKE 'Hiber%'
</sql-query>

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 27, 2005 3:12 pm 
Newbie

Joined: Wed Apr 27, 2005 2:11 pm
Posts: 4
Yeah i saw that brutha but when i add the line return-scalar it errors and says return-scalr must be declared. And if it does work it gives no example on how to code for the result. Could you just offer a little advice instead to just pointing things out. Ihave read the docs and would appeciate a little more clarification


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 27, 2005 3:26 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
are you using the latest hibernate 3?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 27, 2005 3:28 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
http://www.hibernate.org/hib_docs/v3/re ... ting-named

on how to execute the queries.

look in unit test for concrete examples.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 27, 2005 3:30 pm 
Newbie

Joined: Wed Apr 27, 2005 2:11 pm
Posts: 4
Nope my jar file says hibernate2.jar I do not dictate what version to use so i cannot upgrade to version 3.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 27, 2005 3:33 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
then dont use Hibernate 3 features ;)

hibernate 2 does not support native sql scalar values.

_________________
Max
Don't forget to rate


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