title: "failed to lazily initialize a collection of role" in Hibernate
body: <p>I've seen this question asked a lot and I know why it happens, I'm just having issues trying to solve it in my specific case.</p>
  
  <p>I'm converting the project I'm working on from using XML files to map classes to database tables for Hibernate, to using Hibernate annotations. Everything is going fine as long as I'm using basic java types (primitives or class versions of primitives, e.g. int or Integer). But when it comes to my class having a member that is another class of mine, things go south.</p>
  
  <p>One type of issue is when I have OnetoMany relationship.</p>
  
  <p>In the XML file for foo it says this:</p>
  
  <pre><code>&lt;set inverse="true" name="barList"&gt;
      &lt;key&gt;
          &lt;column name="foo_id"/&gt;
      &lt;/key&gt;
      &lt;one-to-many class="com.me.model.dao.Bar" /&gt;
  &lt;/set&gt;
  </code></pre>
  
  <p>In converting this to an annotation, I end up with this:</p>
  
  <pre><code>@OneToMany
  @JoinTable(name = "bar", inverseJoinColumns = @JoinColumn(name = "foo_id"))
  public Set&lt;Bar&gt; getBarList() {
      return barList;
  }
  </code></pre>
  
  <p>I've tried other variations of this (including have a JoinColumn), and I know as it stands it may be incomplete, but like I said, I'm having trouble finding a proper solution to get rid of the lazy initial exception when I'm working with the objects in the view of my MVC. FetchType.EAGER is said to be a workaround and not a solution, but curiously, solutions are not offered. Maybe more information is needed.</p>
  
  <ul>
  <li>My MVC is Wicket 1.4.17.</li>
  <li>My app server is Widlfly (i.e. no web.xml)</li>
  <li>Java version is 8.</li>
  <li>Hibernate, through Maven POM
  
  <ul>
  <li>artifact : hibernate</li>
  <li>version : 3.5.0.ga</li>
  <li>artifact : ejb3-persistence</li>
  <li>version : 1.0.1.GA</li>
  </ul></li>
  </ul>
  
  <p><strong>Edit:</strong> It might be helpful to add that while barList appears in the foo class, there is no reference of any kind to bar in foo in the database. The foo table does have a bar_id.</p>