-->
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.  [ 29 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Capturing the SQL statement from an HQL statement
PostPosted: Mon Dec 06, 2004 2:46 pm 
Regular
Regular

Joined: Tue Nov 30, 2004 4:23 pm
Posts: 62
Hibernate version:2.1.6

Need the capability to pass in an HQL statement and abstract out the resulting database specific SQL statement. I saw that there was a class called QueryTranslator that appeared to do this. Can I accomplish this task with QueryTranslator or with another class?

Thanks,

-jay


Top
 Profile  
 
 Post subject: Re: Capturing the SQL statement from an HQL statement
PostPosted: Tue Dec 07, 2004 6:20 am 
Beginner
Beginner

Joined: Tue Oct 26, 2004 12:45 pm
Posts: 43
Location: Israel
jaybytez wrote:
I saw that there was a class called QueryTranslator that appeared to do this. Can I accomplish this task with QueryTranslator or with another class?


It seems like the QueryTranslator is the cleanest way to do it.
you need to do queryTrans.compile() first.

Jus.


Top
 Profile  
 
 Post subject: How to use the QueryTranslator.compile method?
PostPosted: Tue Dec 07, 2004 8:31 pm 
Regular
Regular

Joined: Tue Nov 30, 2004 4:23 pm
Posts: 62
The javadocs for Hibernate are very frustrutating and leave alot to be discovered. So what exactly is required for the compile method to work. I am not totally sure what the replacements Map is for or the boolean parameter.

Thanks for your help,

-jay


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 07, 2004 8:33 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
When you see packages that are clearly labelled "Internal implementation" in the javadoc, it is best not to try and call them from your business code.

P.S. You will do a lot better at getting answers in this forum if you work on politeness. Just a hint.


Top
 Profile  
 
 Post subject: Thank you for the clarity
PostPosted: Tue Dec 07, 2004 8:56 pm 
Regular
Regular

Joined: Tue Nov 30, 2004 4:23 pm
Posts: 62
Sorry for the comment...I am new to the architecture of Hibernate and very impressed by its features. In no way did I mean any disrespect to individuals on the Hibernate team. I have a lot to learn about Hibernate, in a short amount of time for my project. I am more or less overwhelmed with the functionality because I do not have a significant background in the persistence layer.

I wondered if you could point me to "Internal implementation" portion of the javadoc, because when I view the online api for QueryTranslator, I don't see that comment. Or you may have a better suggestion for the issue we are having?

http://www.hibernate.org/hib_docs/api/n ... lator.html

The issue I am having is dealing with massive searches. We have a specific search strategy that we allow users to utilize, but it has some constraints. One of the constraints is that this particular search strategy can only return results with less than 1000 rows. So to determine if the HQL query the developer is submitting is going to return results that are greater than 1000 rows, we are doing a select count(*) ... (more or less). What we need is the functionality of a scrollable cursor. I am not familiar if whether Hibernate allows this. An architect that I am working with was unsure if they Hibernate supported constants (not sure how that relates to a scrollable cursor). And so we wanted to process the HQL query, captured transformed version of the SQL output, and the alter the SQL statement to be a scrollable cursor query, and submit that straight to the database for a specific record size test. So that we could say scroll to 1001 records and if you can scroll that far, the search is to vague and needs to be made more specific.

Thanks,

-jay


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 07, 2004 9:24 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Packages are classified here:

http://www.hibernate.org/hib_docs/api/

Why on earth would you not just use setMaxResults() to limit the query result set size??


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 07, 2004 11:14 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
Hibernate support scrollable resultset and it work good

Gavin,
Please, explain me why You favorite maxResultSet via scrollable resultset
I see Oracle and maxResultSet make ugly subquery with rownum boundary and it
don't work for oracle 8.0 and less - scrollable resultset is natural for me

regards


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 07, 2004 11:43 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
I see Oracle and maxResultSet make ugly subquery with rownum boundary and it don't work for oracle 8.0 and less


Please don't tell people that things don't work when they do. Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 08, 2004 2:26 am 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
Gavin,
It don't work with oracle 8.0 if it have order by - oracle 8.0 and less don't supprot order by in view
This is test :
Code:
package yu.co.snpe.dbtable.test.hibernate;

import java.util.List;

import yu.co.snpe.dbtable.model.hibernate.FinNks;

import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Query;

public class MaxResultSetTests extends BaseHibernateTests {

    public MaxResultSetTests(String name) {
        super(name);
    }
   
    public void testMaxResultsSuccess1() {
        String query = "from " +  FinNks.class.getName() + " where kon=20100";
        try {
            Query q = getSession().createQuery(query);
            q.setMaxResults(100);
            List list = q.list();
            assertTrue("query",true);
        } catch (HibernateException e) {
            assertTrue("query",false);
        }
    }
    public void testMaxResultsSuccess2() {
        String query = "from " +  FinNks.class.getName() + " where kon=20100 order by nk";
        try {
            Query q = getSession().createQuery(query);
            //q.setMaxResults(100);
            List list = q.list();
            assertTrue("query",true);
        } catch (HibernateException e) {
            assertTrue("query",false);
        }
    }
    public void testMaxResultsFail() {
        String query = "from " +  FinNks.class.getName() + " where kon=20100 order by nk";
        try {
            Query q = getSession().createQuery(query);
            q.setMaxResults(100);
            List list = q.list();
            assertTrue("query",true);
        } catch (HibernateException e) {
            assertTrue("query",false);
        }
    }

}


This is SQL and error :
[/quote]Hibernate: select * from ( select finnks0_.NK as NK, finnks0_.RED as RED, finnks0_.DATD as DATD, finnks0_.DATV as DATV, finnks0_.DUG as DUG, finnks0_.POT as POT, finnks0_.SIFD as SIFD, finnks0_.KIFKUF as KIFKUF, finnks0_.ANAL as ANAL, finnks0_.DUGS as DUGS, finnks0_.POTS as POTS, finnks0_.KON as KON, finnks0_.OPN as OPN, finnks0_.VAL as VAL from SNPE2003.FIN_NKS finnks0_ where (kon=20100 ) ) where rownum <= ?
Hibernate: select finnks0_.NK as NK, finnks0_.RED as RED, finnks0_.DATD as DATD, finnks0_.DATV as DATV, finnks0_.DUG as DUG, finnks0_.POT as POT, finnks0_.SIFD as SIFD, finnks0_.KIFKUF as KIFKUF, finnks0_.ANAL as ANAL, finnks0_.DUGS as DUGS, finnks0_.POTS as POTS, finnks0_.KON as KON, finnks0_.OPN as OPN, finnks0_.VAL as VAL from SNPE2003.FIN_NKS finnks0_ where (kon=20100 ) order by nk
Hibernate: select * from ( select finnks0_.NK as NK, finnks0_.RED as RED, finnks0_.DATD as DATD, finnks0_.DATV as DATV, finnks0_.DUG as DUG, finnks0_.POT as POT, finnks0_.SIFD as SIFD, finnks0_.KIFKUF as KIFKUF, finnks0_.ANAL as ANAL, finnks0_.DUGS as DUGS, finnks0_.POTS as POTS, finnks0_.KON as KON, finnks0_.OPN as OPN, finnks0_.VAL as VAL from SNPE2003.FIN_NKS finnks0_ where (kon=20100 ) order by nk ) where rownum <= ?
[WARN,JDBCExceptionReporter,main] SQL Error: 907, SQLState: 42000
[ERROR,JDBCExceptionReporter,main] ORA-00907: missing right parenthesis

[WARN,JDBCExceptionReporter,main] SQL Error: 907, SQLState: 42000
[ERROR,JDBCExceptionReporter,main] ORA-00907: missing right parenthesis
Quote:

Oracle >=8.1 work fine (it support order by in view)

regards


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 08, 2004 2:48 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Then say "does not work if you have an HQL order by clause on an unsupported version of Oracle". Information about which versions of Oracle are supported may be found here:

http://www.hibernate.org/Documentation/ ... dDatabases

You can of course extend the dialect to add support for previous version of Oracle. But, by definition, unsupported versions are do not work out of the box.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 08, 2004 2:54 am 
Newbie

Joined: Wed Nov 24, 2004 8:38 am
Posts: 19
Location: India
snpesnpe wrote:
Hibernate support scrollable resultset and it work good

I see Oracle and maxResultSet make ugly subquery with rownum boundary
regards


--------------------------------------------------------------------------------------
I am looking for a way to find the SQL generated by HQL. Can u tell me how could we accomplish that......

Thanks........


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 08, 2004 3:40 am 
Senior
Senior

Joined: Sat Jul 17, 2004 5:16 pm
Posts: 143
gs_1481 wrote:
I am looking for a way to find the SQL generated by HQL. Can u tell me how could we accomplish that......

Thanks........


Set your log level to debug, or use the p6spy driver wrapper. Then you will see the SQL.

Chris


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 08, 2004 3:49 am 
Newbie

Joined: Wed Nov 24, 2004 8:38 am
Posts: 19
Location: India
mchyzer wrote:
gs_1481 wrote:
I am looking for a way to find the SQL generated by HQL. Can u tell me how could we accomplish that......

Thanks........


Set your log level to debug, or use the p6spy driver wrapper. Then you will see the SQL.

Chris


Where i need to do the changes to generate that log...........


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 08, 2004 4:02 am 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
Gavin,
I tell version Oracle 8.0 and You quote my message and tell that I am wrong
Jay ask you for limit query result and You tell that he isn't politeness

I like hibernate; use hibernate and I appreciate your work, but it isn't reason that I tell
'milk is black' if Gavin or Christian say it
If your users trust 'anonymous snpe' more than you then you don't appreciate your users

I'm sorry for this, but I want know (like Jay) how limit query - no hard feelings

gs_1481,
You have to set hibernate.show_sql in properties file

best regards


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 08, 2004 4:08 am 
Senior
Senior

Joined: Sat Jul 17, 2004 5:16 pm
Posts: 143
snpesnpe, you were a little imprecise, which is dangerous on a forum that lasts for a long time that people will come back and read. So maybe just be more precise. Incidentally, I like black milk. mmm, chocolate. Chris


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 29 posts ]  Go to page 1, 2  Next

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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.