我目前正在使用 OSGi 进行测试。我正在通过 Eclipse 运行它。我想将我的 DAO 层作为 OSGi 解决方案的一部分,但我的第一个绊脚石是这个错误:
Jun 29, 2009 6:12:37 PM org.hibernate.cfg.annotations.Version <clinit>
INFO: Hibernate Annotations 3.3.0.GA
Jun 29, 2009 6:12:37 PM org.hibernate.ejb.Version <clinit>
INFO: Hibernate EntityManager 3.3.0.GA
Jun 29, 2009 6:12:37 PM org.hibernate.ejb.Ejb3Configuration configure
INFO: Could not find any META-INF/persistence.xml file in the classpath
我尝试将persistence.xml 文件放在很多不同的地方,但无济于事。 关于我做错了什么的任何想法?
有没有办法手动加载persistence.xml?
激活器如下所示:
package com.activator;
public class PersistenceActivator implements BundleActivator {
@Override
public void start(BundleContext arg0) throws Exception {
EntityManagerFactory emf = Persistence
.createEntityManagerFactory("postgres");
EntityManager em = emf.createEntityManager();
SimpleDaoImpl dao = new SimpleDaoImpl();
dao.setEntityManager(em);
}
@Override
public void stop(BundleContext arg0) throws Exception {
// TODO Auto-generated method stub
}
}
这是我的目录结构的样子:
替代文字 http://www.freeimagehosting.net/uploads/7b7b7d2d30.jpg
这是我的清单.MF
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Dao Plug-in
Bundle-SymbolicName: Dao
Bundle-Version: 1.0.0
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: org.osgi.framework;version="1.4.0"
Bundle-Activator: com.activator.PersistenceActivator
Export-Package: com.dao.service
Require-Bundle: HibernateBundle;bundle-version="1.0.0"
HibernateBundle包含所有的 Hibernate 和 Persistence Jars。
这是我的Persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence>
<!-- Sample persistence using PostgreSQL. See postgres.txt. -->
<persistence-unit name="postgres" transaction-type="RESOURCE_LOCAL">
<properties>
<property name="hibernate.archive.autodetection" value="class" />
<!--
Comment out if schema exists & you don't want the tables dropped.
-->
<property name="hibernate.hbm2ddl.auto" value="create-drop" /> <!-- drop/create tables @startup, drop tables @shutdown -->
<!-- Database Connection Settings -->
<property name="hibernate.connection.autocommit">true</property>
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver" />
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
<property name="hibernate.connection.username" value="postgres" />
<property name="hibernate.connection.password" value="postgres" />
<property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/test" />
<!-- Not sure about these... -->
<property name="hibernate.max_fetch_depth">16</property>
<property name="hibernate.jdbc.batch_size">1000</property>
<property name="hibernate.use_outer_join">true</property>
<property name="hibernate.default_batch_fetch_size">500</property>
<!-- Hibernate Query Language (HQL) parser. -->
<property name="hibernate.query.factory_class">
org.hibernate.hql.ast.ASTQueryTranslatorFactory</property>
<!-- Echo all executed SQL to stdout -->
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">false</property>
<!-- Use c3p0 for the JDBC connection pool -->
<property name="hibernate.c3p0.min_size">3</property>
<property name="hibernate.c3p0.max_size">100</property>
<property name="hibernate.c3p0.max_statements">100</property>
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider" />
</properties>
</persistence-unit>
</persistence>
我在清单的类路径中尝试过的事情没有运气:
Bundle-ClassPath: ., META-INF/persistence.xml
捆绑类路径:., ../META-INF/persistence.xml
捆绑类路径:., /META-INF/persistence.xml
捆绑类路径:., ./META-INF/persistence.xml
捆绑类路径:., META-INF
捆绑类路径:., ../META-INF
捆绑类路径:., /META-INF
捆绑类路径:., ./META-INF
Bundle-ClassPath: ., C:\Workspaces\OSGiJPA\Dao\META-INF\persistence.xml
Bundle-ClassPath: ., C:\Workspaces\OSGiJPA\Dao\META-INF