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

NPE for Criteria query containing fetch join as a regression of HHH-12338

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 5.2.17, 5.3.0.Final
    • Fix Version/s: 5.2.18, 5.3.1
    • Component/s: metamodel
    • Labels:
    • Environment:
      Observed with both Wildfly 10.1 and 12.
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

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

      Description

      I'm creating this new issue from an error report added recently to HHH-12338 Closed , which nobody seemed to notice.

      The fix applied for HHH-12338 Closed causes a regression when @ElementCollection and @CollectionTable is used. The following mapping taken from an entity used to work until Hibernate 5.2.16. It causes a NPE for criteria queries starting from 5.2.17.

      @ElementCollection
      @CollectionTable(
      	name = "doc_reader",
      	joinColumns = @JoinColumn(name = "doc_id", nullable = false), foreignKey = @ForeignKey(CONSTRAINT)
      )
      @Column(name = "reader", nullable = false)
      @Convert(converter = RoleConverter.class)
      private Set<Role> readers;
      // Role is an interface whose instances are represented in the database by names (strings), converted to/from by RoleConverter.
      

      Until 5.2.16, the JPA meta model class generated for this entity contains a SetAttribute for readers:

      public static volatile SetAttribute<Doc, Role> readers;
      

      Using 5.2.17, this becomes a SingularAttribute instead, which is obviously wrong (and it seems that @ElementCollection is not taken into account).

      public static volatile SingularAttribute<Doc, Set<Role>> readers;
      

      As a result, the following code then throws a NPE when creating a fetch join (last line). Debugging showed that Doc_.readers is null.

      CriteriaQuery<Doc> q   = b.createQuery(Doc.class);
      Root<Doc> docR = q.from(Doc.class);
      docR.fetch(Doc_.readers);
      

        Attachments

          Issue links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: