-->
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.  [ 4 posts ] 
Author Message
 Post subject: Get the generated query
PostPosted: Wed May 25, 2005 9:38 am 
Newbie

Joined: Wed May 25, 2005 9:31 am
Posts: 2
Hibernate version: 3.0.3

Name and version of the database you are using:MySQL 4.1

I have created a mapping file and added a query to the formula attribute of the property
<property name="xxx" formula=" (select....... where languageCode='EN' and countryCode='US')"/>

I want to parameterize the query in the formula attribute and set the attributes at run time based on the locale setting.
Is it possible to get the query that is generated by hibernate for the default load, so that i can set the parameters of the query before load.
Or is there any other alternative.

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 25, 2005 3:36 pm 
Senior
Senior

Joined: Tue Feb 08, 2005 5:26 pm
Posts: 157
Location: Montréal, Québec - Canada
Maybe you can try using a Filter.

Code:
<hibernate-mapping package="whatever">
   <class name="youName" table="yourtable >
      <property></property>
      <property></property>
      <property></property>
      <set></set>
     

      <filter name="FilterBasedOnCountryAndLanguage" condition="languageCode=:language and countryCode=:country"/>
   
   </class>
   <filter-def name="FilterBasedOnCountryAndLanguage">
      <filter-param name="language" type="java.lang.String"/>
      <filter-param name="country" type="java.lang.String"/>
   </filter-def>
</hibernate-mapping>


Then you can go:
Code:
session.enableFilter("FilterBasedOnCountryAndLanguage").setParameter("language","FRENCH").setParameter("country", "CANADA");


Should work... make sure you understand that filters do not apply to cached data... so they must be setup in the session prior to hitting the database.

Good luck.

_________________
Vincent Giguère
J2EE Developer


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 26, 2005 1:13 am 
Newbie

Joined: Wed May 25, 2005 9:31 am
Posts: 2
I think i was not really clear in explaining the problem.
I have tables
Theme
I18NTheme
Locale

The table Theme contains code and the value is in I18NTheme. The value is set in I18NTheme based on LocaleId and the localeid details are in Locale table. The data to be fetched is based on languagecode and country code.

I want a result for a query like the one below, but using the mappings in hibernate.
select i18.value from i18nTheme i18,Theme t,Locale l
where l.id=i18.localeId and t.id=i18.themeId and
l.countrycode='US' and l.languageCode='EN' and t.id=id

The retrieved value should be available in class Theme.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 27, 2005 11:24 am 
Newbie

Joined: Thu May 26, 2005 4:17 am
Posts: 5
Location: Bangalore
hi,
Its quite easy to get the generated query.Make the folling setting in ur hibernate.cfg.xml file:
<property name="hibernate.show_sql">true</property>

then redeploy ur application and run it .u can see the generated query in ur application server console.

anil

_________________
hi,
I am from b'lore working for "NEXTLINX INDIA LTD".


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