Hi all i have articles and comments tables article comments will be maintained in coments table with thread_code of article(the commments may be from 0 to 1000) my hibernate mapping file contains
Article.hbm.xml
<set name="comments" fetch="select" inverse="false"> <key column="thread_code" property-ref="threadCode"/> <one-to-many class="pkg.Comments" not-found="ignore"/> </set>
related getters and setters i have provided in the bean follows:
public Set getComments() { return comments; }
public void setComments(Set<CommentsVO> comments) { this.comments = comments; } private Set<CommentsVO> comments;
now my use case is i have to get the list of article objects from data base with only comments count
Criteria criteria = session.createCriteria(Articles.class); criteria.createAlias("comments", "c", CriteriaSpecification.LEFT_JOIN); ProjectionList list = Projections.projectionList(); list.add(Projections.groupProperty("id")); list.add(Projections.count("c.threadCode")); criteria.setProjection(list); return criteria.list();
but my query is getting the articles each with a set of comment objects and the comments count here i dont want the hibernate to load set of comments my requirement is to load only the article object with comments count from comments table i want to remove the Set Comments from my mapping file and bean then how can i join the 2 tables to get article and related comments count (not all the comments objects related to the article)
thanks a lot..
|