[hibernate-dev] EMF / EM properties

Steve Ebersole steve at hibernate.org
Sun Jan 24 20:27:12 EST 2010


There have been a few discussions on IRC about handling getProperties()
& setProperty(..) handling in regards to the EMF and EM.  I wanted to
expand this discussion here so that:
1) we get a broader audence/participation;
2) we get a record of the discussion :)

We have to consider 2 axes if you will, the first being the availability
of a particular setting for EM versus EMF and the second being JPA
defined settings versus "vendor specific" settings.  For Hibernate, the
vast majority of "vendor specific" settings are available already from
org.hibernate.cfg.Environment; those happen to be EMF/SF specific for
the most part.

We've added others in the new org.hibernate.ejb.AvailableSettings.  This
is a mix of JPA defined settings plus some additional
Hibernate-EM-specific settings.  I like the idea of
org.hibernate.ejb.AvailableSettings specifically because it consolidates
all the setting names in a single place.

On Friday on IRC Hardy and I began discussing the idea of "Setting"s as
an internal contract that describes how a setting is applied.  Take the
case of EM, there we'd have a series of named Settings that are specific
to EM.  We described a pretty simplistic interface, something like:
interface EntityManageSetting {
    public void apply(SessionImplementor session, Object value);
    public Object determineValue(SessionImplementor session);
}

Then the pseudo-code for EM.setProperty becomes:
public void setProperty(String name, Object value) {
    final EntityManageSetting setting = getSetting( name );
    if ( setting != null ) {
        // recognized setting
        setting.apply( getSessionImplementor(), value );
    }
    //else {
    //    setting was not recognized, ignore per spec
    //}
}

The EntityManager impl would then have a set of settings:
private static Map<String name,EntityManageSetting> settingHandlers
        = new ConcurrentHashMap<String name,EntityManageSetting>();
static {
    settingHandlers.put(
            SHARED_CACHE_RETRIEVE_MODE,
            new EntityManagerSetting() {
                ...
            }
    );
    ...
}

And something similar for EMF.

One thing I did not see an answer for is how changes to a EMF setting is
supposed to affect an existing EM.  Take cache-store-mode; consider:
EntityManagerFactory emf = ...;
emf.setProperty( 
        "javax.persistence.cache.storeMode", 
        CacheStoreMode.BYPASS 
);
EntityManager em = emf.createEntityManager(); 
// Now, by spec em should behave as CacheStoreMode.BYPASS because
//  the store mode is not overridden on it
.setProperty( 
        "javax.persistence.cache.storeMode", 
        CacheStoreMode.USE 
);
// Now what cache-store-mode is in effect for the em?
//  Intuitively I think CacheStoreMode.BYPASS makes the most sense, 
//    but the spec does not say one way or the other that I saw.


-- 
Steve Ebersole <steve at hibernate.org>
Hibernate.org




More information about the hibernate-dev mailing list