Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing both OpneJPA and Hibernate in OSGI environment
    primarykey
    data
    text
    <p>I am writing a modules to persist some data and used <code>OpenJPA</code> as the persistence provider. But now I want to give a configuration option for user to switch between <code>OpenJPA</code> and <code>hibernate</code>. So I wrote a new DaoFactory classes to create <code>EntityManagerFactory</code> and created new persistence unit (<code>My-PU-Hibernate</code>) in <code>persistence.xml</code> for hibernate.</p> <p>Now problem occurs when I create the EntityManagerFactory. My code is,</p> <pre><code>Persistence.createEntityManagerFactory("My-PU-Hibernate", hibernatePropertyMap); </code></pre> <p>My persistence.xml</p> <pre><code>&lt;persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"&gt; &lt;persistence-unit name="My-PU-OpenJPA" transaction-type="RESOURCE_LOCAL"&gt; &lt;class&gt;org.example.testproject.jpa.openjpa.entity.AttachmentDAOImpl&lt;/class&gt; &lt;/persistence-unit&gt; &lt;persistence-unit name="My-PU-Hibernate" transaction-type="RESOURCE_LOCAL"&gt; &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt; &lt;class&gt;org.example.testproject.jpa.openjpa.entity.AttachmentDAOImpl&lt;/class&gt; &lt;/persistence-unit&gt; &lt;/persistence&gt; </code></pre> <p>My Hibernate property map is, </p> <pre><code>"hibernate.connection.datasource", datasource "hibernate.dialect", "org.hibernate.dialect.MySQLDialect" "hibernate.hbm2ddl.auto","update" "hibernate.cache.provider_class", "org.hibernate.cache.NoCacheProvider" "hibernate.cache.use_query_cache", "false" "hibernate.cache.use_second_level_cache", "false" </code></pre> <p>This picks the OpneJPA <code>PersistenceProvider</code> as the correct persistence provider and creates a EntityManagerFactory from OpenJPA persistance provider. It also gives following warning when it is creating the EntityManagerFactory. </p> <pre><code>WARN [Start Level Event Dispatcher] openjpa.Runtime - The configuration property named "openjpa.Id" was not recognized and will be ignored, although the name closely matches a valid property called "openjpa.Id". </code></pre> <p>So when I try to create a entity manager, it gives following error. </p> <pre><code>&lt;openjpa-2.2.0-wso2v1-r128166:129108 fatal user error&gt; org.apache.openjpa.persistence.ArgumentException: A JDBC Driver or DataSource class name must be specified in the ConnectionDriverName property. Available properties in configuration are "org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl@442ce698". at org.apache.openjpa.jdbc.schema.DataSourceFactory.newDataSource(DataSourceFactory.java:72) at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.createConnectionFactory(JDBCConfigurationImpl.java:844) at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getDBDictionaryInstance(JDBCConfigurationImpl.java:602) at org.apache.openjpa.jdbc.meta.MappingRepository.endConfiguration(MappingRepository.java:1510) at org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:518) at org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:443) at org.apache.openjpa.lib.conf.PluginValue.instantiate(PluginValue.java:104) at org.apache.openjpa.conf.MetaDataRepositoryValue.instantiate(MetaDataRepositoryValue.java:68) at org.apache.openjpa.lib.conf.ObjectValue.instantiate(ObjectValue.java:83) at org.apache.openjpa.conf.OpenJPAConfigurationImpl.newMetaDataRepositoryInstance(OpenJPAConfigurationImpl.java:968) at org.apache.openjpa.conf.OpenJPAConfigurationImpl.getMetaDataRepositoryInstance(OpenJPAConfigurationImpl.java:959) at org.apache.openjpa.kernel.AbstractBrokerFactory.makeReadOnly(AbstractBrokerFactory.java:638) at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:203) at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:156) at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:227) at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:154) at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:60) </code></pre> <p>I think above warning and error occurred due to selecting wrong PersistenceProvider. I have debuged the code and verified that hibernate persistence provider also loaded in the OSGI environment. I used <code>geronimo-jpa_2.0_spec</code> <code>v1.0</code> as javax.persistence vendor.</p> <p>Any thoughts on how to select correct persistence provider?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload