-->
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.  [ 5 posts ] 
Author Message
 Post subject: How to query a record to see if it exist without return data
PostPosted: Wed May 11, 2005 1:43 am 
Regular
Regular

Joined: Mon Aug 02, 2004 9:33 am
Posts: 69
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3

Mapping documents:

Name and version of the database you are using:4.1.11

The generated SQL (show_sql=true):

Hi guys,

I am wondering how to query a record without returning all it data, just like :

select 1 from user where user.email = 'user@hibernate.org'
? Thanks in advance !

regards,
Prettyhandling


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 11, 2005 10:32 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
How about something like

select count(*) from User as u where u.email = :userEmail

http://www.hibernate.org/hib_docs/v3/reference/en/html/queryhql.html


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 20, 2005 4:13 am 
Regular
Regular

Joined: Mon Aug 02, 2004 9:33 am
Posts: 69
Hi,

I tried to use

getHibernateTemplate().findByNamedQuery("UserByActivateCode",new Object[] {activateCode});
}


<query name="UserByActivateCode"><![CDATA[
select count(*) from User user where user.activateCode = ?
]]></query>

but I got this exception:

java.lang.ClassCastException: java.lang.Integer

pls help, Thanks !


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 20, 2005 6:44 am 
Beginner
Beginner

Joined: Wed May 04, 2005 5:17 am
Posts: 40
Create an Integer[] instead of Object[].

Also make sure that activeCode is infact a java.lang.Integer.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 20, 2005 9:44 am 
Regular
Regular

Joined: Mon Aug 02, 2004 9:33 am
Posts: 69
I set

hibernate.connection.show_sql=true

and noticed that eventhough I change the Hibernate SQL to select count(*), it 's still select everything from the table.


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