[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-3872) Criteria on alias causes partial collection materialization

Michael Cameron (JIRA) noreply at atlassian.com
Mon Jan 24 14:57:05 EST 2011


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-3872?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=39758#action_39758 ] 

Michael Cameron commented on HHH-3872:
--------------------------------------

Bump. I just ran into this indirectly with Grails use of Hibernate. This difference in results between using a CriteriaSpecification.LEFT_JOIN vs CriteriaSpecification.INNER_JOIN. In the first case, only children rows that match the criteria are used, but with an inner join, the full child collection is lazily loaded when needed. This is surprising behavior on just changing the join type.

Why does changing between CriteriaSpecification.LEFT_JOIN and CriteriaSpecification.INNER_JOIN affect the child rows returned when using criteria? This seems like a defect. Is there a way besides join type to control this behavior explicitly?

> Criteria on alias causes partial collection materialization
> -----------------------------------------------------------
>
>                 Key: HHH-3872
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3872
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: query-criteria
>    Affects Versions: 3.3.0.CR1
>            Reporter: Adrian Moos
>
> I have a parent entity with a one-to-many assocation to a child entity:
> <hibernate-mapping package="ch.bedag.a11.ccinfo.business.entity" default-lazy="false">
> 	<class name="Parent" table="PARENT">
> 		<id name="id" type="long" column="ID" unsaved-value="null">
> 			<generator class="sequence">
> 				<param name="sequence">SEQ_T_PARENT</param>
> 			</generator>
> 		</id>
> 		<set name="children" cascade="all-delete-orphan" inverse="true">
> 			<key column="PARENT_ID" foreign-key="CHILD_FK1"/>
> 			<one-to-many class="Child"/>
> 		</set>
> 	</class>
> 	
> 	<class name="Child" 
> 		<id name="id" type="long" column="ID" unsaved-value="null">
> 			<generator class="sequence">
> 				<param name="sequence">SEQ_T_CHILD</param>
> 			</generator>
> 		</id>
> 		
> 		<property name="businessKey" column="BUSINESSKEY" not-null="true"/>
> 	</class>
> </hibernate-mapping>
> I then do:
>         Criteria parentCriteria = aSession.createCriteria(Parent.class);                
>         parentCriteria.createAlias("children", "c", CriteriaSpecification.LEFT_JOIN);
>         parentCriteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
>                 
>         parentCriteria.add(Restrictions.eq("c.businessKey", 123456789));
>         
>         List parents = parentCriteria.list();
> Expected behaviour: Since each parent in parents is a materialized entity, I'd expect its children set to contain all its children. 
> Observed behaviour: It contains only children with matching business key.
> Is my expectation correct?

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