setFetchMode ignored if using createCriteria

Description

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

Environment

Hibernate 3.2.5, Oracle 8

Activity

Show:
James Randall
January 15, 2014, 4:39 AM

This is working for me with 4.3.0.

I had the same problem with MySql until I added useOldAliasMetadataBehavior=true to the connection string.

jdbc:mysql://localhost:3306/foobar?useOldAliasMetadataBehavior=true

Cheers.

Brett Meyer
April 7, 2014, 5:48 PM

In an effort to clean up, in bulk, tickets that are most likely out of date, we're transitioning all ORM 3 tickets to an "Awaiting Test Case" state. Please see http://in.relation.to/Bloggers/HibernateORMJIRAPoliciesAndCleanUpTactics for more information.

If this is still a legitimate bug in ORM 4, please provide either a test case that reproduces it or enough detail (entities, mappings, snippets, etc.) to show that it still fails on 4. If nothing is received within 3 months or so, we'll be automatically closing them.

Thank you!

Brett Meyer
July 8, 2014, 3:10 PM

Bulk rejecting stale issues. If this is still a legitimate issue on ORM 4, feel free to comment and attach a test case. I'll address responses case-by-case. Thanks!

AndrasS
September 15, 2014, 7:56 PM

@Brett
A lot of projects still have a strong dependency on ORM 3 (e.g. as of Grails 2.3.9 a lot of important plugins only support Hibernate3).
For example, this bug renders the fetch joins expressed as Grails queries unusable (https://jira.grails.org/browse/GRAILS-9829)
It would be very nice if this bug could be fixed in ORM 3 (I believe it works in ORM 4).
I am willing to create a test case if you think it is realistic that this gets fixed (Stian Brattland's example is fairly straightforward)

Brett Meyer
September 15, 2014, 8:26 PM

Sorry , but ORM 3 hasn't been maintained for quite some time. If there's still an issue in ORM 4, we'd be happy to take a look there, provided there's a test case that we could use to reproduce it.

Assignee

Unassigned

Reporter

Peter Weemeeuw

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure