I apologize for the day delay. Ran into a small issue with one of my Gradle plugins after upgrading Gradle for the Hibernate build. Now that that is all sorted...

We are pleased to announce the release of Hibernate Core 4.0.0.Alpha3. Consult the change list for all the gory change details. This is scheduled to be the last Alpha release for Hibernate 4, Beta1 being slated for release on June 1st.

4.0.0.Alpha3 was really about continuing to work on the new metamodel code and fleshing out the new API for SessionFactory creation which leverages that metamodel code as well as the ServiceRegistty code introduced in the first Alpha (and cleaned up since). These things will continue to be the focus for Beta1 too as there is still lots of work to be done on the metamodel code and the SessionFactory building is inherently linked with that work. However, I think the API for SessionFactory building is pretty completely at this point. So I wanted to take the opportunity to introduce that API, even though it is not wired up at this time.

Currently you start off with a ServiceRegistry:

org.hibernate.service.BasicServiceRegistry serviceRegistry = new org.hibernate.service.ServiceRegistryBuilder()
        ... // configure the services

Configuration here means either providing services (or service initiators) directly or providing settings that the services will pick up.

Next, we collect up the metadata sources which are the various sources you want Hibernate to look for metadata describing your domain model and its mapping to the relational database. These sources might be hbm.xml files, annotated classes, etc:

org.hibernate.metamodel.MetadataSources metadataSources = new org.hibernate.metamodel.MetadataSources( serviceRegistry )
        .addResource( "some.hbm.xml" )
        .addAnnotatedClass( SomeEntity.class )

An interesting thing to note here is that we now have a natural lifecycle to the information that used to just get dumped into org.hibernate.cfg.Configuration. This previous step only collects the metadata sources, we still need Hibernate to process them:

org.hibernate.metamodel.Metadata metadata = metadataSources.buildMetadata();

And then finally we build the SessionFactory:

SessionFactory sessionFactory = metadata.buildSessionFactory();

You can even chain many of these steps:

BasicServiceRegistry serviceRegistry = new ServiceRegistryBuilder()
        ... // configure the services

SessionFactory sessionFactory = new MetadataSources( serviceRegistry )
        .addResource( "some.hbm.xml" )
        .addAnnotatedClass( SomeEntity.class )

org.hibernate.cfg.Configuration has been deprecated in this release and org.hibernate.cfg.AnnotationConfiguration has been deprecated for some time now. Both will get removed before 4.0.0 goes Final. We are still planning exactly what the replacement for org.hibernate.ejb.Ejb3Configuration will look like, but it too has been deprecated in the meantime (the recommended way to build an EntityManagerFactory has always been via javax.persistence.Persistence anyway).

We got a lot more aggressive with the package reorganization in this release as well. For those unfamiliar, the general idea is that this is a sort of pre-osgi-ification step, so more will be coming on that front later. The basic gist is that we are splitting packages up based on usages. Stuff deemed part of the API will remain in their same packages, stuff making up the various SPIs will be moved to a 'spi' package, and finally internal (non-public) stuff is moved to an 'internal' package. This work is not yet done, but is moving along.

As always, if you have any comments, the best place is either the hibernate-dev mailing list or the #hibernate-dev IRC channel on freenode. Now is especially the time if you had ideas about any of the planned changes as we move towards 4.0.0.Final or wanted to help in the effort. We have development meetings weekly on the #hibernate-dev IRC channel Mondays at 10am Central time. We also send out minutes to the dev mailing list afterwards.

As always, the release is available from both SourceForge in bundle form as well as the JBoss Nexus repository under the org.hibernate groupId.

Back to top