-->
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: Problem using createSQLQuery and SELECT COUNT(*)
PostPosted: Fri Jan 09, 2004 1:17 pm 
Beginner
Beginner

Joined: Mon Dec 08, 2003 8:09 am
Posts: 25
Hi there,
Im having a problem with getting native SQL to work with a count query. I get the following error message:

net.sf.hibernate.MappingException: No persister for: java.lang.Integer

The method causing the problem is this ultimately this one:
createSQLQuery(getCountQuery(), "a", Integer.class);

I then have some more code which is supposed to make use of the number (returned as an Integer) returned from the query.

The SQL query to run is this one:
SELECT DISTINCT COUNT(*) FROM cks_group a, cks_group_fti f1 WHERE f1.string ~'^stuff' AND a.oid=f1.id;

The stuff after the WHERE is postgreSQL specific Free Text Searching stuff, which is why we have to use native SQL, as Hibernate doesnt currently support using underlying free text searching facilities.

One thing to note is that the return alias never actually appears in the query and isnt needed really (?), however leaving this as "null" simply results in the same error message anyway.

Does anyone know why this exception is being thrown?

Jon


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 09, 2004 1:22 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
createSQLQuery currently can only return Hibernate mapped classes, not primitive values. Use session.connection() to get the JDBC Connection and use a normal JDBC SQL query.


Top
 Profile  
 
 Post subject: Cont...
PostPosted: Fri Jan 09, 2004 1:24 pm 
Beginner
Beginner

Joined: Mon Dec 08, 2003 8:09 am
Posts: 25
This hasnt worked either...same error message

SELECT DISTINCT COUNT(*) {a.*} FROM cks_group a, cks_group_fti f1 WHERE f1.string ~'^null' AND a.oid=f1.id

used in..

createSQLQuery(getCountQuery(), "a", Integer.class);


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 09, 2004 1:26 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
createSQLQuery cant return an Integer! Only mapped classes. As I said, use the JDBC connection from session.connection()


Top
 Profile  
 
 Post subject: Not sure about that
PostPosted: Fri Jan 09, 2004 2:56 pm 
Beginner
Beginner

Joined: Mon Dec 08, 2003 8:09 am
Posts: 25
Hmmm. I dont think youre right there, you know.

I already have HQL queries which do exactly this and utilize the createQuery() method.

Im also pretty sure that I wrote one for createSQLQuery() when we were using mySQL and it worked well. Unfortunately when we changed databases I wiped the rewrote the code and now it doesnt work... and here I am.

But even if you are partially correct and it works for createQuery(), but not for createSQLQuery() .... why?

Jon


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 10, 2004 8:10 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
I am right. HQL is not the same as a createSqlQuery(). It does not work. If you want to know why - read the source. If you want to have it working - submit a patch.


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.