You can try this code:
Code:
public class Author implements Serializable {
@OneToMany(mappedBy = "author", fetch = FetchType.LAZY)
@org.hibernate.annotations.Fetch(org.hibernate.annotations.FetchMode.JOIN)
//you can change JOIN to SUBSELECT
public List<Book> getBooks() {
return books;
}
.....
}
Code:
Session session = HibernateUtil.getSession();
session.beginTransaction();
Criteria c = session.createCriteria(Author.class);
Disjunction disjunction = Restrictions.disjunction();
c.add(disjunction);
List<Author> list = c.list();
for(Author author : list){
System.out.println("No. of books : " + author.getBooks().size());
}
session.getTransaction().commit();
is this what you mean?