Properties parameter does not override persistence.xml entries in createEntityManagerFactory as JPA 2.0 spec requires #121

machadolab opened this Issue Sep 26, 2012 · 3 comments


None yet

3 participants


In my application, we need to pass programmatically the host/port/keyspace/dialect information vs having it stored in the persistence.xml file. I have the following code:

                Map<String, Object> props = new HashMap<String, Object>();

            EntityManagerFactory emf = Persistence.createEntityManagerFactory("cassandra_pu", props);
            EntityManager em = emf.createEntityManager();

and xml:

<persistence-unit name="cassandra_pu">
            <property name="kundera.client.lookup.class" value="com.impetus.client.cassandra.pelops.PelopsClientFactory" />
            <property name="kundera.cache.provider.class" value="com.impetus.kundera.cache.ehcache.EhCacheProvider"/>
            <property name="kundera.cache.config.resource" value="/ehcache-test.xml"/>

Which according to the JPA 2.0 spec, should override those properties from the persistence.xml:

9.4.3 Persistence Unit Properties
Persistence unit properties and hints may be passed to persistence providers in the Map parameter of the
createEntityManagerFactory(String, Map) method. These properties correspond to the
elements in the persistence.xml file. When any of these properties are specified in the Map
parameter, their values override the values of the corresponding elements in the persistence.xml
file for the named persistence unit. They also override any defaults that the provider might have applied.

But instead I get a NPE because the port value is not defined when Pelops tries to load the port configuration item:

java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(
at java.lang.Integer.parseInt(
at com.impetus.client.cassandra.pelops.PelopsClientFactory.createPoolOrConnection(
at com.impetus.kundera.loader.GenericClientFactory.load(
at com.impetus.kundera.configure.ClientFactoryConfiguraton.configure(
at com.impetus.kundera.configure.Configurator.configure(
at com.impetus.kundera.KunderaPersistence.initializeKundera(
at com.impetus.kundera.KunderaPersistence.createEntityManagerFactory(
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
at ......

So it seems kundera should take the supplied properties map and override/add any missing properties before trying to use them to make the connection.

mevivs commented Sep 26, 2012

Yes, i guess this is what it should be doing. valid issue.

@kkmishra kkmishra was assigned Sep 26, 2012
mevivs commented Dec 15, 2012

Fix is available in current trunk branch:

mevivs commented Jan 23, 2013

Fix added and will be released with 2.3


@mevivs mevivs closed this Jan 23, 2013
@kkmishra kkmishra was unassigned by machadolab Feb 13, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment