Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.cantaa.util.spring;
 
 import java.util.Set;
 
Use this instead of LocalContainerEntityManagerFactoryBean to have the opportunity to override persistence-properties from normal input-properties (i.e. from GlobalProperties)

Author(s):
Hans Lesmeister
    private static final Logger log = LoggerFactory.getLogger(CantaaLocalContainerEntityManagerFactoryBean.class);

    
Injected in applicationContext.xml with good old Setter. Properties prefixed with "db." will be used to override persistence-properties
    @Override
    protected PersistenceUnitInfo determinePersistenceUnitInfo(PersistenceUnitManager persistenceUnitManager) {
        PersistenceUnitInfo unitInfo = super.determinePersistenceUnitInfo(persistenceUnitManager);
        mergeAdditionalProperties(unitInfo);
        return unitInfo;
    }

    
If additional properties are specfied then put those properties in the properties that have been read from the persistence.xml, thus overriding properties that where specified in there.

Parameters:
unitInfo Container that (among other stuff) contains the properties from persistence.xml
    private void mergeAdditionalProperties(PersistenceUnitInfo unitInfo) {
        Properties mergableProperties = PropertiesLoader.stripProperties("db"false);
        Set<Stringnames = mergableProperties.stringPropertyNames();
        for (String name : names) {
            String value = mergableProperties.getProperty(name);
            if (!StringUtil.isEmpty(value)) {
                unitInfo.getProperties().setProperty(namevalue);
            }
        }
        .info("** Persistence Properties to be used **");
        PropertiesLoader.logProperties(unitInfo.getProperties());
    }

    
Set Properties to override properties from the persistence.xml

Parameters:
overridingProperties overriding properties
    public void setOverridingProperties(Properties overridingProperties) {
        this. = overridingProperties;
    }
New to GrepCode? Check out our FAQ X