-->
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.  [ 7 posts ] 
Author Message
 Post subject: Best method to use for using Hibernate
PostPosted: Mon Mar 16, 2009 4:54 am 
Newbie

Joined: Tue Mar 10, 2009 10:48 pm
Posts: 18
Hi,

I am very new to Hibernate and has been struggling for weeks.
After reading the documentation of Hibernate, I realised that there are many methods to be used. Eg, Criteria, Named SQL, HQL... etc

I would like to know what is the best method to use when comes to very complicated SQL queries. I need to use one method to do a complicated SQL queries in Hibernate and I am lost in the direction.

Please do give me your kind advise!!
Appreciate it!!


Top
 Profile  
 
 Post subject: Re: Best method to use for using Hibernate
PostPosted: Mon Mar 16, 2009 5:06 am 
Senior
Senior

Joined: Wed Sep 19, 2007 9:31 pm
Posts: 191
Location: Khuntien (Indonesia)
janiceileen wrote:
Hi,

I am very new to Hibernate and has been struggling for weeks.
After reading the documentation of Hibernate, I realised that there are many methods to be used. Eg, Criteria, Named SQL, HQL... etc

I would like to know what is the best method to use when comes to very complicated SQL queries. I need to use one method to do a complicated SQL queries in Hibernate and I am lost in the direction.

Please do give me your kind advise!!
Appreciate it!!


For the complex query, it's better if you use HQL instead of Criteria.
Criteria has a limitation such as cannot join 2 tables or more that don't have any direct association.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 16, 2009 5:17 am 
Newbie

Joined: Tue Mar 10, 2009 10:48 pm
Posts: 18
Sorry, I would like to know more.

Why not named sql but HQL?? To my understanding, HQL is createSQL inside the code. So if my sql queries is very long, then isnt my code very ugly? I may be wrong. Please do advise me.

Appreciate it!!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 16, 2009 5:20 am 
Newbie

Joined: Tue Mar 10, 2009 10:48 pm
Posts: 18
Sorry, I would like to know more.

Why not named sql but HQL?? To my understanding, HQL is createSQL inside the code. So if my sql queries is very long, then isnt my code very ugly? I may be wrong. Please do advise me.

Appreciate it!!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 16, 2009 5:22 am 
Newbie

Joined: Tue Mar 10, 2009 10:48 pm
Posts: 18
Sorry, I would like to know more.

Why not named sql but HQL?? To my understanding, HQL is createSQL inside the code. So if my sql queries is very long, then isnt my code very ugly? I may be wrong. Please do advise me.

Appreciate it!!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 16, 2009 5:34 am 
Senior
Senior

Joined: Wed Sep 19, 2007 9:31 pm
Posts: 191
Location: Khuntien (Indonesia)
Hi,

If you use SQL instead of HQL, maybe some queries will be dependent on particular database.

for example in pagination
Code:
SQL Server:
select top 5 * from user

MySQL:
select * from user limit 0, 5


So it's better using HQL rather than native SQL.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 16, 2009 5:38 am 
Newbie

Joined: Tue Mar 10, 2009 10:48 pm
Posts: 18
Thank you so much. I will focus on using HQL.
Thank you!!!


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