How to clone an object criteria?
I created a Criteria object to join multiple tables and apply multiple constraints. Then I need the total number of records based on the restrictions applied. Then I need to apply the pagination data (using set maxList) and get a list of objects.
Criteria criteria = session.createCriteria(Property.class, "property")
.createAlias("property.propertyType", "type").createAlias(
"property.propertyConcern", "propertyConcern",
CriteriaSpecification.LEFT_JOIN).createAlias(
"propertyConcern.concern", "concern",
CriteriaSpecification.LEFT_JOIN).setResultTransformer(
CriteriaSpecification.DISTINCT_ROOT_ENTITY);
criteria = addMultipleSeachCriteria(criteria, condition);
criteria.setFirstResult(
pageCriteria.getFirstRecordOfCurrentPage())
.setMaxResults(pageCriteria.getRecordsPerPage());
criteria.addOrder(pageCriteria.isSortDescending() ? Order
.desc(pageCriteria.getSortBy()) : Order
.asc(pageCriteria.getSortBy()));
When I run this, I get the results as I expected. But I need to get the number of records for the restrictions applied without applying order and setmaxResults. How can I achieve? I also cannot clone the criteria object.
source
share