-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hibernate Criteria on two related tables !!
PostPosted: Fri May 23, 2008 7:05 am 
Beginner
Beginner

Joined: Mon Oct 30, 2006 12:46 am
Posts: 26
Hi ,

I am new to the hibernate criteria .

I have requirement to get the from two related files like these ..........



Table 1
=====
C.id
name
street
....
....
....

Table 2 :
=====
B.Id
C.id


How can i create criteria to get the data from table1 with name = ""
and B.Id = 2 ?

How we can create link b/t two tables ?/


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 23, 2008 7:48 am 
Newbie

Joined: Fri May 23, 2008 5:43 am
Posts: 13
Location: Switzerland
Quote:
Table 1
=====
C.id
name
street
....
....
....

Table 2 :
=====
B.Id
C.id


I suppose you creaeted entity classes for each table: Class1 for table1 and Class2 for table2. In Class2 there will be many-to-one association
@ManyToOne
@JoinColumn(name="c_id")
Class1 c.
Then you create query like this:

SELECT DISTINCT Class2.c FROM Class2 WHERE Class2.ID = 123 AND Class2.c.name = 'xyz'

I would like to write it more naturally, when c2 is one-to-many assosiated collection:
SELECT Class1 FROM Class1 WHERE Class1.name = 'xyz' AND Class1.c2.ID = 123
but this doesn't work - attemt do dereference collection. Does anyone know how make it work this way?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 27, 2008 5:33 am 
Beginner
Beginner

Joined: Mon Oct 30, 2006 12:46 am
Posts: 26
Hi,


Could any one help me how to write the below HQL in Hibernate criteria....

Select t1 from table1 t1, table2 t2 where t1.CID= t2.CID and t2.id=val;

here val is input from the user.

Table1 :
CID,
data

Table2:
CID
ID



pls pls pls pls pls

Thanks
Praveen Kumar


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