-->
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: ICriteria and DetachedCriteria not sharing a common interfac
PostPosted: Sun Aug 16, 2009 12:18 pm 
Newbie

Joined: Sun Aug 16, 2009 12:09 pm
Posts: 2
Hi guys,

I have the following, I think quite common, scenario.

I have a method in a DAO that builds an ICriteria based on some input filters. The criteria is then applied to different queries, projections etc etc.

Now I got a new requirement where I have to use a detached criteria in order to perform a subquery. Unfortunately, I cannot reuse the existing code to build the criteria because a detached criteria is not an ICriteria. I don't understand why these two don't share a common interface to build criterions and sub criteria.

What would be the appropriate approach to avoid code duplication here?

Regards,
Alex


Top
 Profile  
 
 Post subject: Re: ICriteria and DetachedCriteria not sharing a common interfac
PostPosted: Mon Aug 17, 2009 10:05 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
I don't know, why they don't share a common interface, but you can do this instead:

1) use a DetachedCriteria everywhere. You can then call detachedCriteria.GetExecutableCriteria(session) and execute the query
2) or you can use a Conjunction/Disjunction to build your query and add it to the Criteria/DetachedCritera after you have completed the query definition.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Re: ICriteria and DetachedCriteria not sharing a common interfac
PostPosted: Mon Aug 17, 2009 2:51 pm 
Newbie

Joined: Sun Aug 16, 2009 12:09 pm
Posts: 2
Hi Wolfgang,

thanks for your reply.

I guess 1.) is pretty straightforward. One might wonder why there is an ICriteria then at all?

Cheers,
Alex


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.