Bug 355738 - BatchFetchType.IN does not consider a mappings selection criteria
Summary: BatchFetchType.IN does not consider a mappings selection criteria
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P2 normal with 10 votes (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-24 12:12 EDT by Michael Nielson CLA
Modified: 2022-06-09 10:09 EDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Nielson CLA 2011-08-24 12:12:48 EDT
Using the example here: http://wiki.eclipse.org/EclipseLink/Examples/JPA/MappingSelectionCriteria

OneToOneMapping mapping = (OneToOneMapping)descriptor.getMappingForAttributeName("manager");
ExpressionBuilder builder = new ExpressionBuilder();
        mapping.setSelectionCriteria(builder.getField("EMPLOYEE.DEPT_ID").equal(builder.getParameter("DEPARTMENT.DEPT_ID").
and(builder.getField("EMPLOYEE.POSITION").equal("MANAGER"));

A query on this mapping with an IN batch type will return incorrect results.

query.setHint("eclipselink.batch.type", "IN");
query.setHint("eclipselink.batch", "manager");

They predicate should be: WHERE POSITION = 'MANAGER' AND DEPT_ID IN (...)
They predicate is: WHERE DEPT_ID IN (...)
Comment 1 Michael Nielson CLA 2011-08-30 16:03:51 EDT
This bug does seem like a fairly significant issue as it can lead to data corruption in the identityMap and incorrect batch query results.

As a workaround I've overridden buildBatchCriteria and added an additionalCriteria variable to my mapping.

protected Expression _additionalCriteria;

public Expression getAdditionalCriteria() {
	return _additionalCriteria;
}

public void setAdditionalCriteria(Expression additionalCriteria) {
	this._additionalCriteria = additionalCriteria;
	setSelectionCriteria(buildSelectionCriteria().and(getAdditionalCriteria()));
}

// to ease development
@Override
public void setSelectionCriteria(Expression anExpression) {
	assert false : "setSelectionCriteria should not be called directly, use setAdditionalCriteria instead";
	super.setSelectionCriteria(anExpression);
}

// add in additional criteria to batch query
@Override
protected Expression buildBatchCriteria(ExpressionBuilder builder, ObjectLevelReadQuery query) {
	Expression criteria = super.buildBatchCriteria(builder, query);
	if(getAdditionalCriteria() != null) {
		criteria = criteria.and(getAdditionalCriteria());
	}
	return criteria;
}
Comment 2 Tom Ware CLA 2011-09-22 11:39:08 EDT
Setting target and priority.  See the following page for the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines

Community: Please vote for this bug if it is important to you.  Votes are one of the main criteria we use to determine which bugs to fix next.
Comment 3 Nicolas Marcotte CLA 2014-06-25 17:24:50 EDT
the @JoinFetch(Outer) is also affected by this bug. Should I write a new report with a small self contained test case and link to here or should I open a separate ticket ?
Comment 4 Eclipse Webmaster CLA 2022-06-09 10:09:59 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink