I am trying to use Hibernate 4 only with annotations and hibernate.cfg.xml . I made my own annotation and use reflection to add this to the configuration. I can use Hibernate 4 in this way, but my configuration is built using an obsolete method.
final Configuration configuration = new Configuration(); final Reflections reflections = new Reflections(Item.class.getPackage().getName()); final Set<Class<?>> classes = reflections.getTypesAnnotatedWith(Entity.class); for (final Class<?> clazz : classes) { configuration.addAnnotatedClass(clazz); } return configuration.configure().buildSessionFactory();
(Deprecated code: buildSessionFactory(); ).
Even the hibernate 4 documentation shows how to build a configuration this way.
If I try to use the new method ( buildSessionFactory(ServiceRegistry) , I do not get the same result, and it seems that a lot of unnecessary code does exactly what the obsolete method does anyway. However, I do not want to continue using this style because I don't like using outdated code.
My question is: how to properly configure Hibernate 4 only from the configuration file as described above? I seem to just cause errors and run into unnecessary difficulties.
Teh hippo
source share