Note that there are some explanatory texts on larger screens.

plurals
  1. POCollection not loaded if bean was loaded before as relation
    primarykey
    data
    text
    <p>I have the classes A, B and C. A has a property to B (manytoone) and B has a property to C (onetomany). The classes look like the following ones (shortend to the relevant properties):</p> <pre><code>class A { [...] @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "fkb", nullable = false) private B b; [...] } class B { [...] @OneToMany(mappedBy = "b") @Cascade(value = { CascadeType.ALL }) private Set&lt;C&gt; cs; public Set&lt;C&gt; getCs() { return cs; } [...] } class C { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "fkb", nullable = false) private B b; } </code></pre> <p>The problem is now that depending on the order in which i load As and Bs the collection of Cs in B doesn't work anymore:</p> <pre><code>// outputs correct count of Cs per B List&lt;B&gt; bs = session.createCriteria(B.class).list(); for (B b : bs) { System.out.println(b.getCs().size()); } // outputs always 0 List&lt;A&gt; as = session.createCriteria(A.class).list(); List&lt;B&gt; bs = session.createCriteria(B.class).list(); for (B b : bs) { System.out.println(b.getCs().size()); } </code></pre> <p>The following debugging i have already done:</p> <ul> <li>In the second code hibernate triggers no select statements to load Cs</li> <li>In the first code the returned Bs are of type B and the Set of Cs has type org.hibernate.collection.PersistentSet</li> <li>In the second code the returned Bs are of type B_$$_javassist_58 and the Set of Cs has type java.util.HashSet</li> </ul> <p>I am using Hibernate 3.8.3.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload