No setMaxResults method in DetachedCriteria.
Main Topics
Browse All TopicsHi,
I have OneToMany relationship entities: Client, Doc (documents);
Parent:
@Entity
@Table(name = "CLIENT")
public class Client{
public String getName() {...};
@SuppressWarnings("uncheck
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "client")
public Set<Doc> getDocs(){...}
}
Child:
@Entity
@Table(name = "DOC")
public class Doc{
public String getCode() {...};
...
@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name = "CLIENT_ID", referencedColumnName = "ID")
public Client getClient(){...}
}
I search Clients by Client.name and/or Doc.code, using Hibernate DetachedCriteria.
public class ClientManagerImpl extends HibernateDaoSupport implements ClientManager {
public List<Client> searchClients(String name, String docCode){
DetachedCriteria criteria = DetachedCriteria.forClass(
criteria.createAlias("doc"
if (name is not empty){
criteria.add(Restrictions.
}
if (docCode is not empty){
criteria.add(Restrictions.
}
criteria.setResultTransfor
HibernateTemplate ht = getHibernateTemplate();
ht.setMaxResults(10); // !!!!!!! I want to get a 10 clients max !!!!!! Each users has ~ 5 documents
List<Client> result = ht.findByCriteria(criteria
LogUtils.info("Count of Client:" + result.size());
return result;
}
I expected: If search result > 10 clients, searchClients returns list: 10 clients with all documents.
But realy: MaxResults it is number of rows (clients+documents). 2 clients and not all documents.
How do I set max result for Parent objects, and not restrict the number of children objects?
Sorry for my English
This question is in progress.
Our experts are working on an answer right now.
Sign up for immediate access to the solution once it becomes available.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: dravidnsrPosted on 2009-10-27 at 05:35:30ID: 25671662
criteria.setMaxResults(10)
no need for hibrernatetemplate just try this ...