[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2787) Criteria Aggregate Projections do not JOIN additional tables on which restrictions apply

Sami Dalouche (JIRA) noreply at atlassian.com
Wed Aug 15 06:50:13 EDT 2007


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2787?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_27836 ] 

Sami Dalouche commented on HHH-2787:
------------------------------------

Ok... Sorry It looks like the problem is actually harder to reproduce.. The previous example would work, indeed, and the table join only disappears under more complex circumstances.

Let's say we have 4 entities : 
Entity1 and Entity2, and Entity3 and Entity4

And 1 component : Component1 (mapped as @Embedded)

and the following schema :
Entity1 :
  getEntity2()

Entity2 : 
    getComponent1()

Component1 : 
    getEntity3()
 
Entity3 : 
  getEntity4

Entity4 : 
  anyProperty

Now, let's consider the following code :

Criteria c1 = s.createCriteria(Entity1.class)
.setProjection( Projections.projectionList().add(Projections.rowCount(), "rowCount") );
Criteria c2 = c1.createCriteria("entity2.component1.entity3.entity4", "e4");
c2.add(Restrictions.eq("anyProperty", "anyValue")); 

c1.list();

=> It is going to fail, because the entity3 join just disappears for some reason. (the condition stays in the query)

BUT, what is weird is that the following code would WORK (just removing the projection) :

Criteria c1 = s.createCriteria(Entity1.class)
Criteria c2 = c1.createCriteria("entity2.component1.entity3.entity4", "e4");
c2.add(Restrictions.eq("anyProperty", "anyValue")); 
c1.list();

=> The join is done properly, and the restriction too

And a few additional tests :

Criteria c1 = s.createCriteria(Entity1.class)
.setProjection( Projections.projectionList().add(Projections.rowCount(), "rowCount") );
Criteria c2 = c1.createCriteria("entity2.component1.entity3", "e3");
Criteria c3 = c2.createCriteria("entity4", "e4");
c3.add(Restrictions.eq("anyProperty", "anyValue")); 

=> this WORKS !

And this one :
Criteria c1 = s.createCriteria(Entity1.class)
.setProjection( Projections.projectionList().add(Projections.rowCount(), "rowCount") );
Criteria c2 = c1.createCriteria("entity2", "e3");
Criteria c3 = c2.createCriteria("component1.entity3.entity4", "e4");
c3.add(Restrictions.eq("anyProperty", "anyValue")); 

=> THIS FAILS 

So, there must be some limitation in the way restrictions / joins are handled when dealing with projections..

> Criteria Aggregate Projections do not JOIN additional tables on which restrictions apply
> ----------------------------------------------------------------------------------------
>
>                 Key: HHH-2787
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2787
>             Project: Hibernate3
>          Issue Type: Bug
>          Components: query-criteria
>    Affects Versions: 3.2.5
>         Environment: PostgreSQL Dialect
>            Reporter: Sami Dalouche
>            Priority: Critical
>
> Hi,
> When you have a Criteria Object, on which you  :
> - Add Aggregate Projections such as rowCount()
> - createAlias("whatever").add(Restrictions.*..)
> It looks like that the "whatever" table is NOT joined, even though it is joined OK when the projections are not there.
> So, here is an approximate Unit test that should throw an exception (I couldn't create a complete test case since I couldn't get the unit tests to run on my machine -any link explaining this step somewhere ?):
> Criteria c1 = s.createCriteria(Enrolment.class)
> 			.setProjection( Projections.projectionList().add(Projections.rowCount(), "rowCount") );
> Criteria studentCriteria = c1.createAlias("student", "st");
> studentCriteria.add(Restrictions.eq("name", "whatevername"));
> It should complain saying the "st.name" alias does not exist, because the student class has not been joined.
> Regards,
> Sami Dalouche

-- 
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