-->
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: Best Place to Store Hibernate Queries
PostPosted: Mon Mar 02, 2009 3:03 am 
Newbie

Joined: Mon Mar 02, 2009 2:53 am
Posts: 2
Hi Guys,

Can anybody tell me what could be the best way of storing hibernate queries efficiently ? As of now we are storing it in the class as Public Static final String ..but could there be any better way of doing it. We want to access the same Hql Query from differnt lcoations in our project.

Any help would be greatly appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 02, 2009 4:38 am 
Newbie

Joined: Tue Feb 03, 2009 7:13 am
Posts: 2
I think better to configure all hibernate Queries into hbm file.
If u configure in java file we need to compile that java file for each change .

Thanks,

shekhar.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 02, 2009 4:56 am 
Newbie

Joined: Mon Mar 02, 2009 2:53 am
Posts: 2
shekharreddy wrote:
I think better to configure all hibernate Queries into hbm file.
If u configure in java file we need to compile that java file for each change .

Thanks,

shekhar.


Hi thanks for the response. But I couldn't understand on how to configure queries on hbm files. Can you point out any example or related links ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 02, 2009 5:44 am 
Newbie

Joined: Tue Feb 03, 2009 7:13 am
Posts: 2
eg: OneStop.hbm.xml

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="com.meijer.foodlab.model.domain.OneStop" table="fl_onestop">
<id name="id" type="java.lang.Integer">
<column name="onestop_id" />
<generator class="native" />
</id>

<!-- provide property mapping here --->

</class>

<query name="findByPromotionId">
select onestop FROM OneStop onestop inner join onestop.promotions promotion where promotion.promotionId = :pPromotionId
</query>

</hibernate-mapping>


now get the query string in your dao and execute the query using the following code

Session s = HibernateSupport.currentSession();
Query q = s.getNamedQuery("findByPromotionId");
List lList=q.list();


thanks,

shekhar.


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.