-->
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.  [ 8 posts ] 
Author Message
 Post subject: Need Help with HQL
PostPosted: Thu Jul 05, 2007 9:11 am 
Beginner
Beginner

Joined: Sat Dec 03, 2005 11:12 am
Posts: 27
Hi,

I am having a hard time to write the HQL for this senario

I have two classes Form and FormVersion. Form has a unidirectional one-to-many relation with FormVersion.
FormVersion has all the attributes of the form like name, description, ...
If i want to retrieve a form attribute i have to do form.getFormVersions() which returns a collection of FormVersion objects then, retrieve the attributes of the FormVersion objects.

My problem is i have to write a HQL query for findByFormName() passing the formName parameter. How can i find formName in collection of formVersion objects ( form.getFormVersions() )


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 05, 2007 4:12 pm 
Beginner
Beginner

Joined: Sat Dec 03, 2005 11:12 am
Posts: 27
anybody guys please help!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 06, 2007 4:27 am 
Beginner
Beginner

Joined: Mon Nov 13, 2006 9:43 am
Posts: 30
Hi,

why not to use a named queries?

Take a look at http://www.hibernate.org/hib_docs/refer ... ting-named

Or I understand your requirement not correctly?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 06, 2007 5:00 am 
Regular
Regular

Joined: Mon Apr 02, 2007 3:54 am
Posts: 67
Location: Hyderabad
if you give me ur sql, i can give u corresponding hql ? by using hql only u can get the things that u want. I don't know y r u going for that many things ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 06, 2007 8:16 am 
Beginner
Beginner

Joined: Sat Dec 03, 2005 11:12 am
Posts: 27
javri28,

Yeah I can use named query. But i dont know how to build the query for this requirement.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 06, 2007 8:27 am 
Beginner
Beginner

Joined: Sat Dec 03, 2005 11:12 am
Posts: 27
gopal.knoah ,

My sql looks like this

select * from form f join form_version fv on f.oid=fv.form_oid and fv.name='name version1';

form table form_version table
------ ----------------
oid (pk) oid (pk)
form_oid (fk)
name
.........

The relation is one-to-many


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 06, 2007 8:36 am 
Beginner
Beginner

Joined: Mon Nov 13, 2006 9:43 am
Posts: 30
Hi,

what about something like this:

from packagename.FormVersion as formVersion left outer join formVersion.form as form where form.name := ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 06, 2007 8:49 am 
Regular
Regular

Joined: Mon Apr 02, 2007 3:54 am
Posts: 67
Location: Hyderabad
csr_1978 wrote:
gopal.knoah ,

My sql looks like this

select * from form f join form_version fv on f.oid=fv.form_oid and fv.name='name version1';

form table form_version table
------ ----------------
oid (pk) oid (pk)
form_oid (fk)
name
.........

The relation is one-to-many


In your form_version table, I think form_oid is pk and oid is fk
check it once. I m doing like this.....ok

try in this way now.
Hql :
FROM FormBean F
JOIN F.fv AS formFv
AND formFv.name = 'name version1'

Now go to FormBean.hbm.xml and put this mapping
<many-to-one name = "fv" class = "FormVersionBean" column = "oid" insert = "false" update = "false" />

Now go to FormBean.java and add this field
private FormVersionBean fv;
create its getter and setter

make show_sql true and see the sql at the console converted from this hql. u will get the same sql as u had given to me.

Thanks,
Gopal
[please rate, if helpful]


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