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