Tôi hiện đang thử nghiệm bằng OSGi. Tôi đang chạy điều này thông qua Eclipse. Tôi muốn có lớp DAO của tôi như là một phần của giải pháp OSGi, nhưng trở ngại đầu tiên của tôi là lỗi này:Persistence.xml và OSGi (Equinox)
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
Tôi đã thử đặt các tập tin persistence.xml ở rất nhiều nơi khác nhau, không có kết quả. Bất kỳ ý tưởng nào về những gì tôi đang làm sai?
Có cách nào để tải persistence.xml theo cách thủ công không?
Các activator trông như thế này:
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
}
}
Đây là những gì cấu trúc thư mục của tôi trông giống như:
alt text http://www.freeimagehosting.net/uploads/7b7b7d2d30.jpg
Đây là tôi MANIFEST.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 chứa tất cả các Hibernate và Persistence Chum.
Đây là tôi 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>
Những điều tôi đã cố gắng trong Classpath của Manifest không có may mắn:
Bundle-classpath:., META-INF/persistence.xml
Bundle-classpath:., ../META-INF/persistence.xml
Bundle-classpath:., /META-INF/persistence.xml
Bundle-classpath:., ./META-INF/persistence.xml
Bundle-classpath:. , META-INF
Bundle-classpath:., ../META-INF
Bundle-classpath :.,/META-INF
Bundle-classpath:., ./META-INF
Bundle-classpath:., C: \ Workspaces \ OSGiJPA \ Đạo \ META-INF \ kiên trì .xml
Bundle-ClassPath:., C: \ Workspaces \ OSGiJPA \ Đạo \ META-INF
không may mắn. Tôi đã thử: ** Bundle-classpath:., META-INF/persistence.xml ** ** Bundle-classpath:., ../META-INF/persistence.xml** ** Bundle-ClassPath:., /META-INF/persistence.xml** ** Nhóm-ClassPath:., ./META-INF/persistence.xml** ** Bundle-ClassPath:., META-INF ** ** Bundle-classpath:., ../META-INF** ** Bundle-classpath:.,/META-INF ** ** Bundle-classpath:., ./META- INF ** ** Bundle-ClassPath:., C: \ Workspaces \ OSGiJPA \ Dao \ META-INF \ persis tence.xml ** ** Bundle-ClassPath:., C: \ Workspaces \ OSGiJPA \ Dao \ META-INF ** – systemoutprintln
Không hiển thị đúng, vì vậy tôi đặt nó vào chính bài đăng – systemoutprintln
di chuyển persistence.xml đến gốc của gói jar? Điều đó nên chọn nó lên – bwobbones