The desire for cloned Criteria/DetachedCriteria has also been posted
here and
here.
I have a work-around for my current pagination issues, but as soon as I want to ADD ordering or searching functionality, I'll have to do something similar to return a new instance of the DetachedCriteria.
I actually don't even see why we should be needing to clone criteria. Each method that adds a criterion or sets a projection returns a Criteria. Now, I realize this was done to allow method chaining (criteria.add(...).add(...)... and so on). However, the documentation and the tutorials don't state clearly enough (to my simple mind at least) that these methods have the side effect of changing the orginal criteria.
In fact, even when you get the Executable Criteria from the DetachedCriteria, the DetachedCriteria instance is changed. It seems to me that having these methods have the side effect of changing the actual criteria, when a Criteria is already being returned, is a very confusing API choice. Getting rid of unclear side-effects would also solve the problem. However, if that's the more difficult route, implementing Cloneable is also a perfectly acceptable solution.
So, can anyone indicate to me whether or not one of us (the people recently requesting this behavior) should put this as an issue in JIRA? (Should it be considered a feature request or a bug? I'd guess FR, though the behavior seemed so unintuitive to me that I thought it was a bug at first...)