1 Reply Latest reply on Dec 13, 2018 4:36 AM by Denis Shklyaev

    Hibernate 5.3.7 lazy fetch + getId()

    Denis Shklyaev Newbie

      We are migrating from Wildfly 12 to 15. It seems that new Hibernate version "eagarly" loads lazy dependendent entity when checking its id.

       

      @Entity
      @Table(name = "HOUSE")

      public class House {

         private Long id;

         private String name;

         private Street street;

       

         @Id
         public Long getId() {return id;}

       

         public void setId(Long id) {this.id = id;}

       

         @Column
         public String getName() {return name;}

       

         public void setName(String name) {this.name = name;}

       

         @ManyToOne(fetch = FetchType.LAZY, optional = false)

         @JoinColumn(name = "STREET")

         public Street getStreet() {return street;}

       

         public void setStreet(Street street) {this.street = street;}

      }

       

      @Entity
      @Table(name = "FNN_STREET")

      public class Street {

         private Long id;

         private String name;

         private Collection<House> houses;

       

         @Id
         public Long getId() {return id;}

       

         public void setId(Long id) {this.id = id;}

       

         @Column
         public String getName() {return name;}

       

         public void setName(String name) {this.name = name;}

       

         @OneToMany(mappedBy = "street", fetch = FetchType.LAZY, cascade = CascadeType.REMOVE)

         public Collection<House> getHouses() {return houses;}

       

         public void setHouses(Collection<House> houses) {this.houses = houses;}

      }

       

      Test code:

      House house = em.find(House.class, 2L);

      LOGGER.info(house.getStreet().getId());

       

      This code produces two queries in Wildfly 15 + Hibernate 5.3.7:

      select ... from house where id=?;

      select ... from street where id=?;

       

      All previous Wildfly releases produced just one query due to lazy fetching on many-to-one relation:    select ... from house where id=?;

       

      How can one get proxy id without loading entire entity?