The following expresses the experience I had with hibernate 4.0.0.Final.
The javadoc (distributed under the LGPL license) of the org.hibernate.cfg.Configuration class states that:
NOTE. This will be replaced using ServiceRegistryBuilder and org.hibernate.metamodel.MetadataSources instead of version 4.0, after which this class will become obsolete and scheduled to be removed in 5.0. See HHH-6183 , HHH-2578, and HHH-6586 for details.
After considering question 2578, I used something like this:
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().configure().buildServiceRegistry(); MetadataSources metadataSources = new MetadataSources(serviceRegistry); metadataSources.addResource("some_mapping.hbm.xml") SessionFactory sessionFactory = metadataSources.buildMetadata().buildSessionFactory();
To start reading the configuration, I had to modify the hibernate 3.2.6 configuration and mapping files to use xmlns="http://www.hibernate.org/xsd/hibernate-configuration" and xmlns="http://www.hibernate.org/xsd/hibernate-mapping" , as well as remove the dtd specifications.
I could not find a way to check the mappings defined in hibernate.cfg.xml and sleep mode. the prefix for hibernation-related properties in hibernate.cfg.xml is no longer required.
This might work for some.
For example, I encountered some error because the mapping files contained <cache usage="read-write" /> and ended up using an outdated configuration method:
Configuration configuration = new Configuration().configure(); SessionFactoryImpl sessionFactory = (SessionFactoryImpl) configuration.buildSessionFactory(); EventListenerRegistry listenerRegistry = sessionFactory.getServiceRegistry().getService(EventListenerRegistry.class); SolrIndexEventListener indexListener = new SolrIndexEventListener();
I had to add event listeners programmatically because Configuration is no longer looking for them in hibernate.cfg.xml
Andrei Amariei Dec 15 '11 at 16:59 2011-12-15 16:59
source share