aspose file tools*
The moose likes Object Relational Mapping and the fly likes hibernate Criteria-based join: no left/right outer? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "hibernate Criteria-based join: no left/right outer?" Watch "hibernate Criteria-based join: no left/right outer?" New topic
Author

hibernate Criteria-based join: no left/right outer?

Juan Rolando Prieur-Reza
Ranch Hand

Joined: Jun 20, 2003
Posts: 236
Would someone confirm or clarify to me whether Hibernate supports the use of Criteria and Projections to perform left outer joins (and right outer joins) ? It appears to only support outer joins unless you use HQL.
Thanks


Juan Rolando Prieur-Reza, M.S., LSSBB, SCEA, SCBCD, SCWCD, SCJP/1.6, IBM OOAD, SCSA
Ankur Jain
Greenhorn

Joined: Sep 09, 2008
Posts: 6
Originally posted by juan prieur:
Would someone confirm or clarify to me whether Hibernate supports the use of Criteria and Projections to perform left outer joins (and right outer joins) ? It appears to only support outer joins unless you use HQL.
Thanks


Multiple join Criteria Queries in Hibernate
I wanted to use Hibernate's Criteria API to construct a query against an object with two foreign keys that pointed to two separate tables. I couldn't find any examples of how to join all three tables together using Criteria. I've pasted one below for posterity:

Example ex = Example.create(item).ignoreCase().enableLike(MatchMode.EXACT).excludeZeroes();
//Count full list size
Criteria c = session.createCriteria(Item.class).add(ex);
if(item.getRetailer() != null){
c = c.createAlias("retailer","retailer").add(Expression.eq("retailer.id",item.getRetailer().getId()));
}
if(item.getType() != null){
c = c.createAlias("type","type").add(Expression.eq("type.id",item.getType().getId()));
}
List resultsCount = c.setProjection(Projections.projectionList().add(Projections.rowCount())).list();
listWrapper.setFullListSize((Integer)resultsCount.get(0));

//Return requested page
c.setProjection(null);
c.setResultTransformer(Criteria.ROOT_ENTITY);
c = c.setFirstResult( (pageNum-1)*listPageSize);
c = c.setMaxResults(listPageSize);
if( sortOrder == null || !sortOrder.toLowerCase().startsWith("desc") ){
c = c.addOrder( Order.asc(sortColumn) );
}else{
c = c.addOrder( Order.desc(sortColumn) );
}
listWrapper.setSortCriterion(sortColumn);
listWrapper.setSortDirection(sortOrder);
return c.list();
 
wood burning stoves
 
subject: hibernate Criteria-based join: no left/right outer?