title: Get object by ID in Hibernate
body: <p>I noticed that our senior developer uses following code for retrieving entity by ID:</p>
  
  <pre><code>@Override
  public Source get(Long id) {
      Session session = getSession();
      if( session == null )
          session = sessionFactory.openSession();
      final Source source = (Source)session.load(Source.class, id);
      Hibernate.initialize(source);
      return source;
  }
  </code></pre>
  
  <p>What is benefit of this code? </p>
  
  <p>Why not simply writing </p>
  
  <pre><code>return (Soruce) getSession().get(Source.class, id);
  </code></pre>