私はHibernateをOSGiと連携させているので、このプロジェクトのベースはorg.hibernate.osgi
です。OSGiでHibernateでEntityManagerFactoryを作成
<persistence 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 persistence_2_1.xsd"
version="1.0">
<persistence-unit name="DemoUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
<property name="hibernate.connection.driver_class" value="org.h2.Driver" />
<property name="hibernate.connection.username" value="sa" />
<property name="hibernate.connection.password" value="" />
<property name="hibernate.connection.url" value="jdbc:h2:mem:test;DB_CLOSE_DELAY=-1" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="org.hibernate.FlushMode" value="commit" />
<property name="hibernate.current_session_context_class" value="thread" />
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider" />
<property name="hibernate.show_sql" value="true" />
</properties>
</persistence-unit>
</persistence>
そして、私は次のコードでそれにアクセスしよう:
私は、次ののpersistence.xmlを作成しました
BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext();
ServiceReference serviceReference = context.getServiceReference(PersistenceProvider.class.getName());
PersistenceProvider persistenceProvider = (PersistenceProvider) context.getService(serviceReference);
EntityManagerFactory emf = persistenceProvider.createEntityManagerFactory("DemoUnit", null);
その後、EntityManagerFactory
がnullです。例外もログもログもない。プラグインがpersistence.xmlのを読み込み、それが不正な形式の
org.h2.Driver
にアクセスすることができ、プラグイン失敗
- :私が知っている
- いくつかのソースは、Log4Jなどを使用して
Logger.getLogger("org").setLevel(Level.ALL)
のようなものを使用して例外を取得します。私には行を追加しても変更はありません
誰かが問題の原因を見つけるのに手伝ってもらえますか?
一度に長い時間前に私はOSGi環境でJPAの構成に関するいくつかのメモを書いたhttps://gusto77.wordpress.com/2013/03/27/simple -working-jpa-project-in-osgi-environment / – gusto2