-->
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: how to get/compare sub query result with main query
PostPosted: Wed Mar 04, 2009 3:37 am 
Newbie

Joined: Wed Mar 04, 2009 3:26 am
Posts: 2
Hello All,

I have a query like

Select P.name,subresult.f2,subresult.f2
(select f1,f2,f3 from pojo1 p1,pojo2 p2
where p1.f4=p2.f8) subresult , pojo3 P
where subresult.f3=P.f1

1) How to write the same in HQL

2) How to call a view ? in HQL

Can any body assist on this.

Thanks

_________________
suresh


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 04, 2009 4:27 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
1) There is no from-clause in your outer-query. That doesn't seem right.

2) You can map an entity to a view so that you can use this entity in HQL.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 04, 2009 5:55 am 
Newbie

Joined: Wed Mar 04, 2009 3:26 am
Posts: 2
Hi

My query is missing the keyword "from" and is


Select P.name,subresult.f2,subresult.f2
from
(select f1,f2,f3 from pojo1 p1,pojo2 p2 where p1.f4=p2.f8) subresult ,
pojo3 P
where subresult.f3=P.f1

1) can you tell me how to write using HQL
(Here we are comparing subquery result with some other class object)
(how do I refer/name subquery result )
2) Can anybody give me example for mapping entities with views using HQL

_________________
suresh


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 04, 2009 1:46 pm 
Regular
Regular

Joined: Mon Jan 05, 2009 6:42 pm
Posts: 99
Location: IL
I'm sure there are many posts in this forum to map a Database View to an entity.

in your case you need to create a database view
create view subresult as
select f1,f2,f3 from pojo1 p1,pojo2 p2
where p1.f4=p2.f8

create a POJO which will have the setters and getter's matching the column names and

create hibernate .hbm file describing the mapping from database view to POJO.

Then in HQL:-
Select P.name,subresult.f2,subresult.f2
subresult, pojo3 P
where subresult.f3=P.f1

see this as reference:-
http://forum.hibernate.org/viewtopic.ph ... highlight=

hope this helps,
Latha.


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.