What is the best way of extracting property values from JPA persistence.xml if you want it to work for EclipseLink too? -


i realize possible parse persistence.xml myself, know if there better way extract properties persistence.xml, example values of database driver/url/user/password, in way working both hibernate , eclipselink (and other implementations too) ?

i suppose should able use method "entitymanagerfactory.getproperties()" purpose maybe there bug in eclipselink ?

when using file "/meta-inf/persistence.xml" this:

<persistence ...>     <persistence-unit name="mypersistenceunit" transaction-type="resource_local">         <provider>org.hibernate.jpa.hibernatepersistenceprovider</provider>         ...         <properties>             <property name="javax.persistence.jdbc.driver" value="org.h2.driver"/>             <property name="javax.persistence.jdbc.url" value="jdbc:h2:~/myh2databasefile"/>             ... 

then following code works expected hibernate (5.0.7 latest version) retrieve database url value:

entitymanagerfactory emf = persistence.createentitymanagerfactory("mypersistenceunit"); map<string, object> properties = emf.getproperties(); system.out.println(properties.get("javax.persistence.jdbc.url")); // "jdbc:h2:~/myh2databasefile" 

however, when switching implementation eclipselink (2.6.2 latest version) provider instead specified in persistence.xml:

<provider>org.eclipse.persistence.jpa.persistenceprovider</provider> 

then not work, , can see properties object empty properties.size() == 0.

considering works expected hibernate, suppose bug in eclipselink ? (though possibility have misunderstood how use "getproperties" happens works hibernate because of unknown reason pragmatic programmer coined "programming coincidence")

maybe eclipselink developer reading question , can confirm known bug (which fixed soon) ?

since "entitymanagerfactory.getproperties()" not seem work jpa implementations (eclipselink), there other standard method available (i.e. without using third part libraries e.g. parses xml code) can used extracting property values works both eclipselink , hibernate ?


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -