In a thread[1] today on the Apache Aries user mailing list, some
questions were posed about the EntityManagerFactoryBuilder interface
defined in the JPA Service specification.

To summarize, the core question is: for a given persistence unit (and
thus a EntityManagerFactoryBuilder service instance), is it supported to
invoke createEntityManagerFactory() more than one time with a different
set of properties?

For example, if you had a persistence unit named Accounting would the
following code be supported (this is based on the example in 127.3.4):

// predefined
// username1, username2, password1, password2, url1, url2 - all Strings

ServiceReference[] refs =
   context.getServiceReferences(
       EntityManagerFactoryBuilder.class.getName(),
       "(osgi.unit.name=Accounting)");

if (refs != null) {
    EntityManagerFactoryBuilder emfBuilder =
        (EntityManagerFactoryBuilder) context.getService(refs[0]);
    if (emfBuilder != null) {
        Map<String,Object> props = new HashMap<String,Object>();
        props.put("javax.persistence.jdbc.user", username1);
        props.put("javax.persistence.jdbc.password", password1);
        props.put("javax.persistence.jdbc.url", url1);

        EntityManagerFactory emf1 =
            emfBuilder.createEntityManagerFactory(props);

        props.put("javax.persistence.jdbc.user", username2);
        props.put("javax.persistence.jdbc.password", password2);
        props.put("javax.persistence.jdbc.url", url2);

        EntityManagerFactory emf2 =
            emfBuilder.createEntityManagerFactory(props);

        ...
    }
}

The suggestion in the aries-user thread seems to be that the second call
to createEntityManagerFactory() will throw an IllegalArgumentException
will be thrown, as described in section 127.5.4, but AFAICT, this
section specifically applies to EntityManagerFactory services registered
by the JPA Service provider and doesn't apply to
EntityManagerFactoryBuilder nor to EntityManagerFactory instances
created by EntityManagerFactoryBuilder.

Thanks,
Justin


[1] http://aries.markmail.org/thread/6mjz3ih2cipg7rs3
_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev

Reply via email to