Hibernate retrieve null for OneToMany collection
<p>My problem is that hibernate retrieve <strong>null</strong> in the value of the <code>@OneToMany Set organizationMemberCollection</code> when fetching an instance on the following object : </p>

<p><strong>UserAccount.java</strong> :</p>

<pre><code>@Entity
@Table(name="USER_ACCOUNT")
public class UserAccount {

    @Id
    @Column(name = "id", nullable = false)
    @SequenceGenerator(name = "generator", sequenceName = "USER_ACCOUNT_id_seq", allocationSize=1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "generator")
    private Long id;

    @Column(name = "EMAIL", nullable = false)
    private String email;

    @Column(name = "PASSWORD_HASH")
    private String passwordHash;

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "userAccount")
    private Set &lt;OrganizationMember&gt; organizationMemberCollection;

    ...

    /*
     * getters and setters
     */
}
</code></pre>

<p>Here is the Object that "owns" the association :</p>

<p><strong>OrganizationMember.java</strong> :</p>

<pre><code>@Entity
@Table(name="ORGANIZATION_MEMBER")
public class OrganizationMember{

    @Id
    @Column(name = "id", nullable = false)
    @SequenceGenerator(name = "generator", sequenceName = "ORGANIZATION_MEMBER_id_seq", allocationSize=1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "generator")
    private Long id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "USER_ACCOUNT_ID", nullable = false)
    private UserAccount userAccount;    

    ...

    /*
     * getters and setters
     */
}
</code></pre>

<p>In this application we have two different configuations :</p>

<ul>
<li><p><strong>Production</strong>, where Hibernate is connected to a PostgreSQL database.
Here is the sessionFactory configuration for prod :</p>

<p><code>&lt;bean id="sessionFactory"
    class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"&gt;
    &lt;property name="hibernateProperties"&gt;
        &lt;props&gt;
            &lt;prop key="hibernate.jdbc.batch_size"&gt;10&lt;/prop&gt;
            &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
            &lt;prop key="hibernate.cglib.use_reflection_optimizer"&gt;false&lt;/prop&gt;
        &lt;/props&gt;
    &lt;/property&gt;
    ...
&lt;/bean&gt;</code></p></li>
<li><p><strong>Test</strong>, where Hibernate is conencted to an in memory HSQLDB database :</p>

<p><code>&lt;bean id="sessionFactory"
        class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"&gt;
        &lt;property name="hibernateProperties"&gt;
            &lt;props&gt;
                &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.HSQLDialect&lt;/prop&gt;
                &lt;prop key="hibernate.show_sql"&gt;false&lt;/prop&gt;
                &lt;prop key="hibernate.cglib.use_reflection_optimizer"&gt;false&lt;/prop&gt;
                &lt;prop key="hibernate.hbm2ddl.auto"&gt;create-drop&lt;/prop&gt;
                &lt;prop key="hibernate.cache.use_second_level_cache"&gt;false&lt;/prop&gt;
                &lt;prop key="hibernate.cache.use_query_cache"&gt;false&lt;/prop&gt;
            &lt;/props&gt;
        &lt;/property&gt;
        ...
    &lt;/bean&gt;</code></p></li>
</ul>

<p>This issue only show up in testing configuration; In production configuration everything's going nicely and I can get the collection.
However, when I fetch an UserAccount in the test configuration I get <code>null</code> in the <code>organizationMemberCollection</code> property (Not an empty Set).</p>

<p>After some hours of research through google and Hibernate's doc I still haven't found any post relating to the same issue/behaviour, so I'm a lillte bit lost and help would be greatly appreciated !</p>

<p>I can of course provide more information if needed, Thanks !</p>

<h1>Edit :</h1>

<p>Test higlighting the problem :</p>

<pre><code>@Test
@Transactional
public void testFindUserAccount_OrganizationMemberCollectionFetching() {

    assertNotNull(userAccountDao.findUserAccount("user1@test.fr"));  //NoProblem
    assertNotNull(userAccountDao.findUserAccount("user1@test.fr").getCabinetMemberCollection());  //Fails

}
</code></pre>

<p>With the following <code>findUserAccount</code> dao</p>

<pre><code>public UserAccount findUserAccount(String email) {
    if (email == null) {
        return null;
    }
    UserAccount userAccount = (UserAccount) this.sessionFactory
            .getCurrentSession().createCriteria(UserAccount.class)
            .add(Restrictions.eq("email", email).ignoreCase())
            .uniqueResult();
    if (userAccount == null) {
        throw new ObjectNotFoundException("UserAccount.notFound");
    } else {
        return userAccount;
    }
}
</code></pre>