[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-879) Enable joining the same association twice with Criteria

Aleksei Valikov (JIRA) noreply at atlassian.com
Wed Sep 20 05:46:27 EDT 2006


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-879?page=comments#action_24561 ] 

Aleksei Valikov commented on HHH-879:
-------------------------------------

Hi Christian,

I've digged relatively deep in the Criteria API code.
Unfortunatelly there's no simple fix for that.

(sorry for terminology, I'm not a Hibernate developer)
As Gavin said somewhere in the forum, Criteria API comes historically from entity loaders. They solve entity loading tasks quite well BUT they are not exactly the solution for querying. I mean, if Criteria query has a structure that corresponds to the query structure of entity loaders - than it's fine.

When it's not (like duplicate join) then you simply can't make it work. In the case of multiple joins, the API enforces the check of duplicates - and it has very good reasons for that.

So what I understood from my studies, Criteria has a nice API but a wrong architecture.

At the same time HQL does not suffer these constaints at all. Because HQL was intended as querying API from the very start, where Criteria was not.
 
Like all of you commenters and watchers I also had a task to programmatically create queries. And I've spent several days trying to make Criteria API work on queries a bit more complicated than thos presented in the documentation. After a large number of fruitless efforts I' finally gave up.

My solution was to create an own programmatic API where I could formulate queries in a way similar to Criteria API. Unlike the Criteria API, my queries are finally converted to HQL, not SQL.

Here's an example:

>From record = From.clazz(Record.class, "record");
QueryRule.
  from(record).
  where(record.property("name").like(Constant.quotedString("%a%"))).
  selectDistinct(record.property("id").as("id"));

> Enable joining the same association twice with Criteria
> -------------------------------------------------------
>
>          Key: HHH-879
>          URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-879
>      Project: Hibernate3
>         Type: Improvement

>   Components: core
>     Reporter: Vladimir Bayanov

>
>
> Make double joining the same association with Criteria.createCriteria possible. See: http://forum.hibernate.org/viewtopic.php?t=931249

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira




More information about the hibernate-issues mailing list