We're updating the issue view to help you get more done. 

EntityGraph and isMember functions generates illegal sql

Description

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.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 @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.

1 2 3 4 5 6 7 8 9 10 11 12 13 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.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 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 )

Environment

None

Status

Assignee

Unassigned

Reporter

Oliver Breidenbach

Fix versions

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

5.0.3
4.3.9

Priority

Major