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)

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
    protected PersistenceUnitInfo determinePersistenceUnitInfo(PersistenceUnitManager persistenceUnitManager) {
        PersistenceUnitInfo unitInfo = super.determinePersistenceUnitInfo(persistenceUnitManager);
        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.

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)) {
        .info("** Persistence Properties to be used **");

Set Properties to override properties from the persistence.xml

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