-->
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.  [ 5 posts ] 
Author Message
 Post subject: Issue about assemble where clause dynamicly.
PostPosted: Tue Jun 15, 2004 10:42 pm 
Newbie

Joined: Tue Jun 15, 2004 1:10 am
Posts: 5
Code:
    String hql="select * from Tog t where t.f1=:pf1 and t.f2=:pf2 and t.f3=:pf3"
    Query q = session.createQuery(hql);
    q.setString("pf1","vf1");
    q.setString("pf2",null);
    q.setString("pf3","vf1");


Is there an approach to get the target sqls as follows by setting some FLAG in Hibernate respectively?
Code:
1: target output SQL: "select * from Tbl_Tog t where t.f1=? and t.f2 IS NULL and t.f3=?"
corresponding param: q.setString("pf2",null); //the input "null" param is substituted by "IS NULL"

2: target output SQL: "select * from Tbl_Tog t where t.f1=? and t.f3=?"
corresponding param: q.setString("pf2",null); //the sub where clause is omitted


IMHO,the following methods should be added into Query object to achieve such function:
Code:
public Query setIsNull(String name);// to change "t.f2=:pf2" to "t.f2 IS NULL"
public Query setIsNull(int position);

public Query setOmitted(String name);// to omit the sub where clause "t.f2=:pf2"
public Query setOmitted(int position);



Thanks a lot!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 21, 2004 3:00 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Check the Query by Example for the Omited stuff

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 21, 2004 6:48 am 
Newbie

Joined: Tue Jun 15, 2004 1:10 am
Posts: 5
Hi,emmanuel :
Thanks your reply,Could you please explain it more detailedly,I did not quite catch you.

Thanks a lot!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 22, 2004 7:21 pm 
Regular
Regular

Joined: Tue Oct 07, 2003 10:20 am
Posts: 77
I think he's saying to have a look at http://www.hibernate.org/hib_docs/reference/en/html/querycriteria.html#querycriteria-examples.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 28, 2004 12:19 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
sdknott wrote:


Hehe yes

_________________
Emmanuel


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