-->
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: Hot to use QueryTranslator
PostPosted: Mon Aug 01, 2005 7:19 am 
Regular
Regular

Joined: Thu Sep 04, 2003 10:43 am
Posts: 61
Hibernate version:
3.0.5
Mapping documents:
Not meaningfull
Code between sessionFactory.openSession() and session.close():
SessionFactory sf = config.buildSessionFactory();
Session hibSession = sf.openSession();
String HQL4Tranlsate = "SELECT coalesce(sum(a.id), 0) FROM table1 AS a";
ClassicQueryTranslatorFactory cqt = new ClassicQueryTranslatorFactory();
QueryTranslator qt = cqt.createQueryTranslator(HQL4Tranlsate, new HashMap(), (SessionFactoryImplementor)sf);
qt.compile(new HashMap(), false );
String result = qt.getSQLString();
System.out.println(result);
hibSession.createQuery(HQL4Tranlsate).list();

Full stack trace of any exception that occurs:
No exception
Name and version of the database you are using:
Oracle 9.0.2.0
The generated SQL (show_sql=true):
See below
Debug level Hibernate log excerpt:

The problem is that the result of the QueryTransator is different from the SQL I get executing the query. In fact from the above "System.out.println(result);" i get:
select coalesce(sum(tstdacmain0_.id), 0) as col_0_0_ from tst_main tstdacmain0_

while if I execute the query I see:

Hibernate: select nvl(sum(tstdacmain0_.id), 0) as col_0_0_ from tst_main tstdacmain0_

Why there is this difference? Did I use the wrong method to translate HQL to SQL?
In my real case I have to use the QueryTranslator to build a part of a query which will be completed with another part in SQL (I can't write the whole query in HQL since Hibernate won't compile it), so, in few words I really need to have the correct translation usually made by Hibernate.
Thankfull for helps
Alessandro Rizzi


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 01, 2005 9:34 am 
Regular
Regular

Joined: Thu Sep 04, 2003 10:43 am
Posts: 61
I wrote this message for anyone who will have the same problem as me:

My mistake was the use of old "classic" instead of AST. If you change the first line of code with:

ASTQueryTranslatorFactory cqt = new ASTQueryTranslatorFactory();

Everything will work.

Sorry for bothering the team with this question.

Ragards
Alessandro


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