Fixed
Details
Assignee
UnassignedUnassignedReporter
Oliver BreidenbachOliver BreidenbachLabels
Components
Priority
Major
Details
Details
Assignee
Unassigned
UnassignedReporter
Oliver Breidenbach
Oliver BreidenbachLabels
Components
Priority
Created April 20, 2015 at 12:55 PM
Updated February 10, 2016 at 5:13 PM
Resolved February 8, 2016 at 11:44 AM
When an EntityGraph uses an attribute which is also used for isMember where function an illegal sql is generated.
Having to entities: Foo and Bar. Entity Bar is holding a collection of Foos.
@Entity public static class Foo { @Id private Long id; @ManyToOne public Bar bar; } @Entity public static class Bar { @Id private Long id; @ManyToMany(targetEntity = Foo.class, cascade = CascadeType.ALL) @JoinTable(name = "bar_foo", joinColumns = { @JoinColumn(name = "bar_id") }, inverseJoinColumns = { @JoinColumn(name = "foo_id") }) public Set<Foo> foos = new HashSet<Foo>(); }
Using EntityGraph for attribute foos and using isMember function in the where clause.
CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Bar> cq = cb.createQuery(Bar.class); Root<Bar> from = cq.from(Bar.class); Expression<Set<Foo>> foos = from.get("foos"); cq.where(cb.isMember(foo, foos)); TypedQuery<Bar> query = em.createQuery(cq); EntityGraph<Bar> barGraph = em.createEntityGraph( Bar.class ); barGraph.addAttributeNodes("foos"); query.setHint("javax.persistence.loadgraph", barGraph);
Will end in an illegal sql.
SELECT bar0_.id AS id1_0_0_, foos1_.id AS id1_1_1_, foos1_.bar_id AS bar_id1_0_0__, foos1_.foo_id AS foo_id2_4_0__ FROM Bar bar0_ WHERE ? IN ( SELECT foos1_.foo_id FROM bar_foo foos1_ WHERE bar0_.id=foos1_.bar_id )