title: Hibernate 4 Annotation Configuration
body: <p>I'm trying to use Hibernate 4 with annotations only, and a <code>hibernate.cfg.xml</code> file.  I've made my own annotation and am using reflection to add this to the configuration.  I'm able to use Hibernate 4 in this manner fine, but my configuration is being built using a deprecated method.</p>
  
  <pre><code>final Configuration configuration = new Configuration();
  final Reflections reflections = new Reflections(Item.class.getPackage().getName());
  final Set&lt;Class&lt;?&gt;&gt; classes = reflections.getTypesAnnotatedWith(Entity.class);
  for (final Class&lt;?&gt; clazz : classes) {
      configuration.addAnnotatedClass(clazz);
  }
  return configuration.configure().buildSessionFactory();
  </code></pre>
  
  <p>(Deprecated code: <code>buildSessionFactory();</code> ).</p>
  
  <p>Even the hibernate 4 documentation shows to build the configuration in that manner.</p>
  
  <p>If I try to use the new method (<code>buildSessionFactory(ServiceRegistry)</code>, I don't get the same result, and it seems like a lot of unnecessary code to do exactly what the deprecated method does anyway.  However, I don't want to keep using this style, because I dislike using deprecated code anyway.</p>
  
  <p><em>My question is:</em> How do I correctly configure Hibernate 4 from just a configuration file in the manner described above?  I seem to just cause errors &amp; face unnecessary difficulties.</p>