Forums Register Login

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

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
 

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();
Just the other day, I was thinking ... about this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 7992 times.
Similar Threads
Old style SQL vs new style SQL
Using Right outer Joins in Hibernate with My SQL.
best way for storing Java objects into DB
How does Hibernate handle a nullable foreign key in a query?
Left Inner join with EJB QL
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 09:44:08.