-->
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.  [ 9 posts ] 
Author Message
 Post subject: Subqueries
PostPosted: Tue May 15, 2007 11:00 am 
Newbie

Joined: Tue May 15, 2007 10:55 am
Posts: 3
Hi,

I have just started working on Hibernate.
I have a doubt about subqueries.
My query in Oracle is
select * from ( select * from tabelname where ID=12 order by dtCreation desc ) where rownum <= 4;

Please let me know how I can use the query in hibernate.

Thanks in advance.
Sri.


Top
 Profile  
 
 Post subject: Subqueries
PostPosted: Tue May 15, 2007 12:15 pm 
Beginner
Beginner

Joined: Wed Apr 18, 2007 6:17 pm
Posts: 49
Location: Dominican Republic
Hello, what kind of queries do you plan to use, hql or SQL?


Top
 Profile  
 
 Post subject: Subquery
PostPosted: Wed May 16, 2007 1:13 am 
Newbie

Joined: Tue May 15, 2007 10:55 am
Posts: 3
Hi,

I want to use hql queries.

Im using a List and want to populate the list using the query.
Here I require help in writing the hql query inside the createQuery.

queryList = session.createQuery("select * from ( select * from tabelname where ID=12 order by dtCreation desc ) where rownum <= 4").list();

thanks in advance.
sri


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 16, 2007 1:23 am 
Regular
Regular

Joined: Mon Mar 26, 2007 12:38 am
Posts: 119
Hi,
HQL subqueries may occur only in the select or where clauses.
So, we cannot have inline views in HQL.

-----------------------------------------
Rate the reply if you find it helpful


Top
 Profile  
 
 Post subject: Subquery
PostPosted: Wed May 16, 2007 1:50 am 
Newbie

Joined: Tue May 15, 2007 10:55 am
Posts: 3
Hi,

Is this not possible in anyway to do In Hibernate??

Thanks,
Sri


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 16, 2007 3:52 am 
Regular
Regular

Joined: Mon Mar 26, 2007 12:38 am
Posts: 119
Hi,
It's not possible with HQL.
Definitely possible with Hibernate.
Use session.createSQLQuery().

-----------------------------------------
Rate the reply if you find it helpful


Top
 Profile  
 
 Post subject: Re: Subqueries
PostPosted: Wed May 16, 2007 4:41 am 
Senior
Senior

Joined: Sat Apr 21, 2007 11:01 pm
Posts: 144
srilkrishna wrote:
Hi,
I have just started working on Hibernate.
I have a doubt about subqueries.
My query in Oracle is
select * from ( select * from tabelname where ID=12 order by dtCreation desc ) where rownum <= 4;
Please let me know how I can use the query in hibernate.
Thanks in advance.
Sri.

How about just keeping things simple...
In Hibernate you select from an Object not a table. instead of trying to do everything in one go, just break it up.

HQL1: "from tablename where bla bla bla" will give you your table name, you can then use a simple if statment to convert this to your fully qualified Object name which should be the same as MyObject.class.getName() for example.

Then you can do your 2nd peice of HQL.

HQL2: "from <Object name from if statment before> where bla bla"

There isn't any need to do everything in one statement as you did with SQL. Keep things simple with Hibernate and you'll get on with it much better.

_________________
Everytime you get an answer to your question without giving credit; god kills a kitten. :(


Top
 Profile  
 
 Post subject: Subqueries
PostPosted: Wed May 16, 2007 9:47 am 
Beginner
Beginner

Joined: Wed Apr 18, 2007 6:17 pm
Posts: 49
Location: Dominican Republic
i agree with adamgibbons, why you just split the queries, as i've heard sometimes it's faster for some databases.


Top
 Profile  
 
 Post subject: Re: Subqueries
PostPosted: Thu May 24, 2007 5:49 am 
Newbie

Joined: Thu May 24, 2007 5:38 am
Posts: 1
adamgibbons wrote:
srilkrishna wrote:
Hi,
I have just started working on Hibernate.
I have a doubt about subqueries.
My query in Oracle is
select * from ( select * from tabelname where ID=12 order by dtCreation desc ) where rownum <= 4;
Please let me know how I can use the query in hibernate.
Thanks in advance.
Sri.

How about just keeping things simple...
In Hibernate you select from an Object not a table. instead of trying to do everything in one go, just break it up.

HQL1: "from tablename where bla bla bla" will give you your table name, you can then use a simple if statment to convert this to your fully qualified Object name which should be the same as MyObject.class.getName() for example.

Then you can do your 2nd peice of HQL.

HQL2: "from <Object name from if statment before> where bla bla"

There isn't any need to do everything in one statement as you did with SQL. Keep things simple with Hibernate and you'll get on with it much better.


Hi adamgibbons,

I am also newbie with Hibernate. Can you describe more in detail, how you applying new select statement on the existing select result.

Thanks in advance.
Sergio


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