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.

@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 )

Activity

Oliver BreidenbachNovember 12, 2015 at 8:21 AM

Can I do anything to get the fix merged into the master?

Steve EbersoleOctober 29, 2015 at 4:09 AM

Thanks for verifying Oliver!

Oliver BreidenbachOctober 28, 2015 at 7:58 PM
Edited

This bug also affects version 5.0.3. The test in the PR demostrates the bug. It alos contains a 'fix'. Not sure, if it is the correct solution.

Steve EbersoleOctober 28, 2015 at 3:24 AM

As part of verifying that this issue affects 5.0, please just set the "Affects version". Leave the "verify-affects-5.0" label and leave the issue in "Awaiting Response" status; these are critical for us to be able to track these verifications and triage them. Thanks.

Steve EbersoleOctober 27, 2015 at 7:17 PM

This bug report does not indicate that the reported issue affects version 5.x. Versions prior to 5.x are no longer maintained. It would be a great help to the Hibernate team and community for someone to verify that the reported issue still affects version 5.x. If so, please add the 5.x version that you verified with to the list of affected-versions and attach the (preferably SSCCE) test case you used to do the verification to the report; from there the issues will be looked at during our triage meetings.

For details, see http://in.relation.to/2015/10/27/great-jira-cleanup-2015/

Fixed

Details

Assignee

Reporter

Labels

Components

Fix versions

Affects versions

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

Flag notifications