[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-3524) setFetchMode ignored if using createCriteria

Stian Brattland (JIRA) noreply at atlassian.com
Fri Aug 7 07:46:12 EDT 2009


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

Stian Brattland commented on HHH-3524:
--------------------------------------

I'm having the exact same problem using Hibernate 3.2.5.ga and MySQL 5.1. I have disabled the query cache.

The workaround introduced by Richard Ogin does not work for me. I can confirm that invoking createCriteria() or createAlias() on any existing Criteria object makes
Hibernate ignore everything that has been set through setFetchMode().

The following Criteria succeeds:

Criteria a = getSession().createCriteria(AlbumHierarchyNode.class);
a.setFetchMode("albums", FetchMode.JOIN).setFetchMode("albums.album", FetchMode.JOIN).setFetchMode("albums.album.library", FetchMode.JOIN);
a.add(Restrictions.isNotNull("parent"));
a.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
a.list();

The following Criteria fails:

Criteria a = getSession().createCriteria(AlbumHierarchyNode.class);
a.setFetchMode("albums", FetchMode.JOIN).setFetchMode("albums.album", FetchMode.JOIN).setFetchMode("albums.album.library", FetchMode.JOIN);
a.createCriteria("albums").createCriteria("album").add(Restrictions.in("status", filter.getStatuses()));
a.add(Restrictions.isNotNull("parent"));
a.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
a.list();

> setFetchMode ignored if using createCriteria
> --------------------------------------------
>
>                 Key: HHH-3524
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3524
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: query-criteria
>    Affects Versions: 3.2.5
>         Environment: Hibernate 3.2.5, Oracle 8
>            Reporter: Peter Weemeeuw
>         Attachments: test.case.tar.gz
>
>
> Hi,
> It seems that criteria.setFetchMode gets ignored if you combine it with createCriteria to add a restriction.
> This works as expected:
> DetachedCriteria c = DetachedCriteria.forClass(MenuItem.class);
> c.setFetchMode("menuItemSubscriptions", FetchMode.JOIN);
> But in this case the join doesn't happen (and I get a LazyInstantiationException further on).
> DetachedCriteria c = DetachedCriteria.forClass(MenuItem.class);		
> c.setFetchMode("menuItemSubscriptions", FetchMode.JOIN);
> c.createCriteria("menuItemSubscriptions").add(
> 	Restrictions.eq("location", "B")
> );
> This does not happen if I set lazy="false" in the mappings
> file.
> Regards,
> Peter

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