-->
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.  [ 1 post ] 
Author Message
 Post subject: Generic DAO collections exception handling
PostPosted: Tue Dec 27, 2005 9:34 am 
Newbie

Joined: Tue Dec 27, 2005 8:02 am
Posts: 3
Location: Belgium
Hi guys,

I'm using the Generic DAO pattern from Hibernate in Action for my JBoss application, but I'm faced with the following problem.

When a parameter in a named query is a collection (e.g. "select b from MyBean b where b.id in (:collectionparam)") and the parameter is set with an empty collection, then an exception is thrown. This is normal, because the EJB specs say that the collection should have at least one entry.

This means that for each method of each implementation of a DAO where collections are used, an extra check must be performed.
For instance:

Code:
public List<MyBean> getByIds(Collection<Integer> ids) {
     
    // exra check
    if ( (ids == null) || (ids.size == 0) ) return new LinkedList<MyBean>();

    // the rest of the code
    Query query = getSession.getNamedQuery(MYQUERY);
    query.setParameter("collectionparam", ids);
    return query.list();

}


Does anyone have a proposal so that this simple check does not need to be replicated? (Perhaps by using an abstract class for each DAO, but wouldn't this be too much overhead....)

Any input would help


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.