문제

현재 OSGI를 사용하여 테스트 중입니다. 나는 이클립스를 통해 이것을 실행하고 있습니다. OSGI 솔루션의 일부로 DAO 레이어를 갖고 싶지만 첫 번째 걸림돌은 다음 오류입니다.

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 모든 최대 절전 모드 및 지속성 항아리가 들어 있습니다.

여기, 내 것이요 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>

내가 운이없는 Manifest의 클래스 경로에서 시도한 것들 :

번들 계급 경로 :., meta-inf/persistence.xml

번들 클래스 경로 :., ../meta-inf/persistence.xml

번들 클래스 경로 :., /meta-inf/persistence.xml

번들 클래스 경로 :., ./meta-inf/persistence.xml

번들 계급 경로 :., 메타 인프

번들 계급 경로 : ../meta-inf

번들 계급 경로 : /meta-inf

번들 계급 경로 :., ./meta-inf

번들 클래스 경로 :., C : Workspaces Osgijpa dao meta-inf persistence.xml

번들 클래스 경로 :., C : Workspaces osgijpa dao meta-inf

도움이 되었습니까?

해결책

나는 persistence.xml을 사용하지 않고 Hibernate.cfg.xml이 비슷합니다.

src/main/resource/hibernate/hibernate.cfg.xml

내 활성기에서 나는 번들 컨텍스트를 통해 파일을 받고있다 : 여기에 몇 가지 예제 코드가 내가 수행하고 해당 파일을 참조하는 방법이있다 :>

private void initHibernate(BundleContext context) {
        try {
            final AnnotationConfiguration cfg = new AnnotationConfiguration();
            cfg.configure(context.getBundle().getEntry("/src/main/resource/hibernate/hibernate.cfg.xml"));
            sessionFactory = cfg.buildSessionFactory();

        } catch (Exception e) {
            // TODO Auto-generated catch block
        }
    }

보시다시피, 구성 파일을 가져 오는 줄은 다음과 같습니다.

context.getBundle().getEntry("/src/main/resource/hibernate/hibernate.cfg.xml")

보시다시피 내 Hibernate.cfg.xml은 Meta-Inf 폴더 내부에 있지 않습니다. /src /......의 루트 폴더에 있습니다.

도움이되기를 바랍니다.

크리스토프

다른 팁

사용 eclipselink 다음과 같은 이유는 최대 절전 모드 및 기타 구현을 잊어 버립니다.

  • 클래스 로더를 너무 많이 놀아야합니다 ...Thread.CurrentThread (). SetContextClassLoader(...)

  • Bundle-ClassPath 속성을 설정하고 JAR 번들을 설치하는 대신 수동으로 종속성을 추가하려는 유혹을받습니다.

  • 당신은 얻을 것이다 제공자는 찾을 수 없습니다 오류 또는 찾을 수 없을 수도 있습니다 Persistence.xml

위의 모든 노력은 많은 시도 후에 효과가 없을 수 있습니다.

그러나 eclipselink를 사용하면 브레이너가 아니며 구현은 OSGI 환경에서 상자 밖으로 작동하도록 설계되었으며 클래스 로딩 두통이 없습니다.

  1. (제안 만) : 게으른 로더를 사용하는 경우 대신 활성기에 작업을 수행하는 것이 좋습니다. 예를 들어 Simpledaoimpl 대조업체로 호출되는 싱글 톤을 사용하십시오.
  2. SRC 폴더 (src/meta-inf/persistent.xml)에서 meta-inf/persistent.xml을 이동하면 Meta-Inf 폴더가 클래스 경로에 있지 않기 때문에 런타임 모드에서만 작동하기 때문입니다.
  3. eclipselink jpa osgi를 사용하는 경우, JPA-PersistenceUnits 항목이 누락되었습니다. 추가하다

    JPA-PersistenceUnits : Postgres

    선언문으로 .mf.

  4. 그런 다음 시작 구성에서 org.eclipse.persistence.jpa.osgi의 시작 레벨을 설정하십시오 (ecliselink 2.3.x : org.eclipse.persistence.jpa는 2.1.x의 경우)과 Javax.persistence의 시작 레벨 1으로 1로 1입니다.

행운을 빕니다. 실제로 2.3은 배포에 문제가 있으며 Bundleresource를 처리하지 않습니다 : // xxxx urls :(, 2.1.2는 매우 잘 작동합니다.)

클래스 경로에 메타 인프가 포함 된 디렉토리가 있어야합니다. 각 디렉토리는 Meta-Inf를 검색하고 찾은 경우 persistence.xml을 검색합니다.

클래스 경로에 "meta-inf"를 넣으면 해당 디렉토리에 또 다른 메타 INF가 필요합니다.

매니페스트에서 이와 같은 번들 클래스 경로를 사용해보십시오

번들 클래스 경로 :., /location/of/persistence.xml

Meta-Inf 디렉토리는 클래스 경로에 없습니다. 이것은 단순히 당신의 아래에 배치하여 작동해야합니다 SRC 더러스토리. 별도의 위치에 원한다면 해당 디렉토리를 포함시키기 위해 번들 클래스 경로를 지정해야합니다. 기본적으로 ClassPath는 '입니다.'.

나도 같은 문제가 발생합니다.

Eclipse 링크가 OSGI 환경에서 사용하는 최선의 옵션이라고 생각합니다. JPA 구현과 함께 기본적으로 작동하기 때문에 문제가 없습니다. Hibernate로 이동 해야하는 경우 Persintece.xml 구성 및 일부 Libs를 교체하십시오.

속성을 설정해야합니다 (최대 절전 모드는 다릅니다) :

javax.persistence.provider = org.apache.openjpa.persistence.persistenceproviderimpl

전화 :

Persistence.CreateEntityManagerFactory (EntityManagerFactoryName, Properties)

작동하게합니다.

앞에서 언급했듯이 클래스 로더 포장이 필요합니다. ClassLoaderEntityManager를 사용할 수 있습니다 https://issues.apache.org/jira/browse/openjpa-1783 하기 위해서.

문안 인사

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top