-->
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.  [ 2 posts ] 
Author Message
 Post subject: Conditional IS NULL using prepared statement binding
PostPosted: Mon Jun 07, 2004 6:10 pm 
Beginner
Beginner

Joined: Sat Aug 30, 2003 1:36 am
Posts: 47
Location: Calgary, AB
I am wondering what the best practice for this situation would be, here is code that works, notice the if(itemKey == null) condition, what I would like to have there in the else portion is:
q += " and acl.itemKey = ?;

But I can't do that unless I change the whole sess.find statement and doing some more conditionals, is there a cleaner way?

Code:
String q = "select acl from " + AccessLevel.class.getName()
                + " acl where acl.groupKey = ? "
                + " and acl.realm = ?";

        if (itemKey == null) {
            q += " and acl.itemKey IS NULL";
        } else {
            q += " and acl.itemKey = '" + itemKey + "'";
        }
        //Couldn't do the IS NULL condition above using prepared statement, so took it out
        // todo: sql escape the itemKey string
        List groups = sess.find(q,
                new Object[]{group.getId(), realm},
                new Type[]{Hibernate.INTEGER, Hibernate.STRING});
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 08, 2004 1:36 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
better to use criteria API


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