-->
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: Adding a condition in WHERE clause
PostPosted: Fri May 11, 2007 1:12 am 
Newbie

Joined: Fri May 11, 2007 12:54 am
Posts: 2
Hi,

Lets say my db have the following tables:

TABLE-A TABLE-B
Col1(PK) ColB1
Col2 ColB2
Col3 ColB3
Col4
Col5

In TABLE-A, Col1 is mapped to Generator Class in hbm file.

In TABLE-B, my contents will be

ColB1 ColB2 ColB3
-----------------------------------
1 121 N
2 131 N
3 141 Y (Only one row will have 'Y')


I want to map the TABLE-A with this TABLE-B such that I get the SQL as follows:

SELECT <column-list of Table-A> FROM TABLE-A WHERE Col1=1 AND Col5=(SELECT ColB2 FROM TABLE-B WHERE ColB3='Y')

How do I change my hbm file for this?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 11, 2007 5:14 am 
Regular
Regular

Joined: Mon Mar 26, 2007 12:38 am
Posts: 119
Hi,
Use a class level filter for A.
<filter name="myFilter"
condition=" col5 = (SELECT ColB2 FROM TABLE-B WHERE ColB3='Y') "/>


If you are new to filters,
http://www.hibernate.org/hib_docs/v3/re ... lters.html
----------------------------------------
Rate the reply if you find it helpful


Top
 Profile  
 
 Post subject: Adding a condition in WHERE clause
PostPosted: Mon May 14, 2007 5:28 am 
Newbie

Joined: Fri May 11, 2007 12:54 am
Posts: 2
Thanks for the code.

Is it possible to have such a filter in UPDATE clause ?

something like

UPDATE TABLE-A SET Col2='blah-blah', Col3='bgg' WHERE Col1=1 AND Col5=(SELECT ColB2 FROM TABLE-B WHERE ColB3='Y')


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.