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: Fastest way to check if a record Exists ??? (HOW)
PostPosted: Thu Dec 07, 2006 9:28 am 
Beginner
Beginner

Joined: Wed Sep 13, 2006 7:24 am
Posts: 26
Using Hibernate 3.1.3

What would be the fastest way (performance/memory wise) to check the existance of a record.

a basic method would be to do a

Code:
   private boolean idExists(Session session, String id) {
        List list = session.createQuery("From Stuff s where s.idCol = :id1")
        .setString("id1", id)
        .setReadOnly(true)
        .setFetchSize(1)
        .setCacheable(true)
        .list();
        return (list.size() > 0) ;
    }


but is there a faster way of doing this ? I have 2nd level caching turned on with EnCahce

Thanks

_________________
Ben


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 07, 2006 10:13 am 
Beginner
Beginner

Joined: Tue Nov 28, 2006 4:26 pm
Posts: 32
Location: Montreal, Quebec, Canada
Hibernate Tips & Tricks suggest to use UniqueResult. That's what I use.


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.