[hibernate-dev] HHH-7018 and one more change to how we serialize EntityManagerFactory instances...

Scott Marlow smarlow at redhat.com
Mon Feb 6 23:32:01 EST 2012


Feedback is welcome on a proposed change for HHH-7018 
https://github.com/scottmarlow/hibernate-orm/commit/007e7f17eed10c6c1db55a7d9c90b7126c5a5ae2

When we serialize the EntityManagerFactory in 4.0.0, there can be 
nonserializeable objects in the EMF configuration properties (e.g. 
JTA_PLATFORM, datasource, other stuff).  In most cases, we will have a 
session factory name (preferred) or persistence unit name to uniquely 
identify the EntityManagerFactory.  In 4.0.1, during serialization, we 
only serialize the (hopefully) unique name.

If a duplicate EntityManagerFactory is created (by name), no immediate 
error is given, instead we only give an error later when deserializing 
the EMF. The HibernateException thrown during deserialization will look 
like:
    "registry contains more than one (" +
     entityManagerFactorySet.size()+ ") entity manager factories: "
     + name

If that causes issues for any application, the SESSION_FACTORY_NAME can 
be passed in from the troubled application (possibly with 
SESSION_FACTORY_NAME_IS_JNDI set to false but true is also fine).

For the 4.1 release, I would like to take this one step further.  The 
above changes, only were made for EntityManager serialization of the EM 
to EMF reference.  The next step is to apply the same change to the EMF 
readObject/writeObject, such that we also allow the EMF to be serialized 
when it contains nonserializable objects.  This also simplifies the EM 
serialization, as it can just use default serialization for the EMF.

The proposed commit (to be fixed in 4.1) is at 
https://github.com/scottmarlow/hibernate-orm/commit/007e7f17eed10c6c1db55a7d9c90b7126c5a5ae2.

Feedback on the change is welcome (we are building 4.1 final middle of 
this week).

Scott



More information about the hibernate-dev mailing list