Hibernate JIRA | Quentin Ambard | 6 years ago
Click on the to mark the solution that helps you, Samebug will learn from it.
As a community member, you’ll be rewarded for you help.
  1. 0

    There is an error fetching a collection of a subitem. This affect empty collections : a proxy is intialized on the collection, even fetched. Accessing to this collection fire a new request. Here is a simple mode. Please see test case for complete implementation: @Entity @Table( name = "ITEM" ) public class Item { @Id @GeneratedValue private Long id; @OneToOne(cascade = { CascadeType.ALL }, optional = true, fetch = FetchType.LAZY, orphanRemoval = true) @JoinColumn(name = "SUB_ITEM_ID") private SubItem subItem ; ... } public class SubItem { @Id @GeneratedValue private Long id; @ElementCollection(targetClass = String.class, fetch = FetchType.LAZY) @CollectionTable(name = "PHONES") @Column(name = "PHONE", nullable = false) private List<String> phones ; ... } the following hql request "from Item i left join fetch i.subItem left join fetch i.subItem.phones" generates this sql request : select as id2_0_, as id1_1_, item0_.SUB_ITEM_ID as SUB2_2_0_, phones3_.SubItem_id as SubItem1_1_0__, phones3_.PHONE as PHONE0__, phones3_.SubItem_id as SubItem1_1_0__, phones3_.PHONE as PHONE0__ from ITEM item0_ left outer join SUB_ITEM subitem1_ on left outer join SUB_ITEM subitem2_ on left outer join PHONES phones3_ on There is an extra left outerjoin. QueryClassLoader.initialize(SelectClause selectClause) can't find the collectionOwner for the PHONES collection : collectionFromElement.getOrigin()is about the second left outer join : "SUB_ITEM subitem2_ on" and the fromElementList is based on the first outer join "subitem1_ on". The following hql request doesn't work either : from Item i left join fetch i.subItem s left join fetch s.phones Request is correctly generated, but the left outer join collectionPersisters is null java.lang.NullPointerException at org.hibernate.loader.BasicLoader.isBag( at org.hibernate.loader.BasicLoader.postInstantiate( at org.hibernate.loader.hql.QueryLoader.<init>( at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile( ... see attached test case for full stack

    Hibernate JIRA | 6 years ago | Quentin Ambard

    Root Cause Analysis

    1. java.lang.NullPointerException

      No message provided

      at org.hibernate.loader.BasicLoader.isBag()
    2. Hibernate
      1. org.hibernate.loader.BasicLoader.isBag(
      2. org.hibernate.loader.BasicLoader.postInstantiate(
      3. org.hibernate.loader.hql.QueryLoader.<init>(
      4. org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(
      4 frames