Uploaded image for project: 'Hibernate ORM'
  1. HHH-9735

EntityGraph and isMember functions generates illegal sql

    Details

    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
      true
    • Sprint:

      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
          )
      

        Attachments

          Activity

            People

            • Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: