-->
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.  [ 2 posts ] 
Author Message
 Post subject: HQL count for a boolean result
PostPosted: Tue Nov 23, 2004 3:29 pm 
Newbie

Joined: Sun Nov 21, 2004 7:52 pm
Posts: 7
Location: Montr
Hibernate version:2.1.6

I need to know if a relationship exist between two organizations.

The following code works fine, but is there a better way to do it with HWL, without using a count(*) ?

I know that queryByExemple of criteria can do the job, but i don't want to use criteria.

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

StringBuffer buffer = new StringBuffer();
buffer.append("SELECT count(*) FROM BusinessRelationship AS br ");
buffer.append("WHERE br.firstOrg = :firstOrg ");
buffer.append("and ");
buffer.append("br.secondOrg = :secondOrg");

Query query = session.createQuery(buffer.toString());
query.setEntity("firstOrg", firstOrg);
query.setEntity("secondOrg", secondOrg);

Object obj = query.uniqueResult();

return new Boolean(((Integer)obj).intValue() > 0);



Name and version of the database you are using: Oracle

thanks

_________________
Hibernate user, trying to get the best of it.


Top
 Profile  
 
 Post subject: Re: HQL count for a boolean result
PostPosted: Wed Nov 24, 2004 10:59 am 
Newbie

Joined: Sun Nov 21, 2004 7:52 pm
Posts: 7
Location: Montr
ledome20 wrote:
Hibernate version:2.1.6

I need to know if a relationship exist between two organizations.

The following code works fine, but is there a better way to do it with HQL, without using a count(*) ?

I know that queryByExemple of criteria can do the job, but i don't want to use criteria.

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

StringBuffer buffer = new StringBuffer();
buffer.append("SELECT count(*) FROM BusinessRelationship AS br ");
buffer.append("WHERE br.firstOrg = :firstOrg ");
buffer.append("and ");
buffer.append("br.secondOrg = :secondOrg");

Query query = session.createQuery(buffer.toString());
query.setEntity("firstOrg", firstOrg);
query.setEntity("secondOrg", secondOrg);

Object obj = query.uniqueResult();

return new Boolean(((Integer)obj).intValue() > 0);



Name and version of the database you are using: Oracle

thanks

_________________
Hibernate user, trying to get the best of it.


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