Bug 366156 - Selection criteria seems to have no effect at least when using DescriptorCustomizer
Summary: Selection criteria seems to have no effect at least when using DescriptorCust...
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P2 major with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-12-09 04:32 EST by Thomas CLA
Modified: 2022-06-09 10:33 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas CLA 2011-12-09 04:32:46 EST
Build Identifier: 20110916-0149

EclipseLink seems to ignore selection criteria, see example to reproduce.

See also discussion here: http://www.eclipse.org/forums/index.php/t/263267/

Reproducible: Always

Steps to Reproduce:
Example to reproduce the error:

Entities (excerpt):
=================================
@Entity
@Table(name="A")
@Customizer(ActStateFilter.class)
public class A{

@JoinTable(name = "AB", joinColumns = @JoinColumn(name = "m_id", referencedColumnName = "m_id"), inverseJoinColumns = @JoinColumn(name = "s_id", referencedColumnName = "s_id"))
private B activeB;
}

@Entity
@Table(name="B")
public class B{

@Id
@Column(name="s_id", unique=true, nullable=false)
private Integer sID;

@Column(name="value", length=60)
private String value;
}


DescriptorCustomizer:
=================================
public class ActStateFilter implements DescriptorCustomizer {
@Override
public void customize(ClassDescriptor descriptor) throws Exception {
OneToOneMapping mapping = (OneToOneMapping) descriptor.getMappingForAttributeName("activeB");

ExpressionBuilder eb = new ExpressionBuilder(mapping.getReferenceClass());
Expression exp = eb.getTable("A").getField("m_id").equal(eb.getParameter("M_ID")).
and(eb.getTable("AB").getField("m_id").equal(eb.getTable("A").getField("m_id"))).
and(eb.getTable("AB").getField("s_id").equal(eb.getTable("B").getField("s_id")).
and(eb.getTable("AB").getField("active").equal(true)));

mapping.setSelectionCriteria(exp);
}
}

Now if I execute the following query:

TypedQuery<A> q = em.createQuery("select a from A a where a.activeB.s_id=10", A.class);

I get all A where the active B's s_id is 10 as expected.

But if instead I execute the following query:

TypedQuery<A> q = em.createQuery("select a from A a where a.activeB=:state", A.class);
B state = em.find(B.class, 10);
q.setParameter("state", state);

I get all A for which there is a B in history with s_id = 10 - regardeless of the active s_id.
Comment 1 Tom Ware CLA 2011-12-22 10:38:25 EST
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 2 Eclipse Webmaster CLA 2022-06-09 10:33:28 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink