0

私は、Hibernate を使用した Eclipse RCP アプリケーションに取り組んでいます。hibernate マッピング (daos など) 用の「サービス」プラグインを作成しました。テストのために、このプラグインに「メイン」クラス/メソッドを作成しました。「メイン」が実行HibernateUtil.initSessionFactory();され、すべてのマッピングに関してデータベースに対していくつかのクエリが実行されます。それは正常に動作します。HibernateUtil.initSessionFactory();「ui」などの別のEclipseプラグインから同じメソッドを実行すると、次のメッセージが表示されます。

java.lang.ExceptionInInitializerError: org.hibernate.MappingNotFoundException: リソース: de/da/service/data/TblItem.hbm.xml が見つかりません

マッピングを含める場合の例外:

addResource("de/da/service/data/TblItem.hbm.xml")


同じメソッドのローカル呼び出しが正常に機能しているのに、なぜこれが起こるのですか?

public static void initSessionFactory() {

    try {
        SessionFactory sf = getSessionFactory(sessionFactory);
        Session s = sf.getCurrentSession();
        s.beginTransaction();
        s.getTransaction().commit();
    }
    catch (Throwable ex) {
        if (ConnectionException.analyze(ex)) {
            throw new ConnectionException();
        }
    }
}

public static SessionFactory getSessionFactory() {
    SessionFactory current = null;
    if (config == null)
        config = new AnnotationConfiguration().configure();

    current = getSessionFactory(sessionFactory);
    return current ;
}

private static SessionFactory getSessionFactory(SessionFactory sFactory) {

    if (sFactory == null) {
        try {

            config = new AnnotationConfiguration().
            setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLInnoDBDialect").
            setProperty("hibernate.current_session_context_class", "thread").
            setProperty("hibernate.connection.driver_class", "org.gjt.mm.mysql.Driver").
            setProperty("hibernate.connection.url", "jdbc:mysql://localhost:3306/db").
            setProperty("hibernate.connection.username", "username").
            setProperty("hibernate.connection.password", "password").
            setProperty("hibernate.connection.pool_size", "0").
            setProperty("hibernate.connection.autocommit", "true").
            setProperty("hibernate.show_sql", "true").
            setProperty("hibernate.format_sql", "true").
            setProperty("hibernate.jdbc.batch_size", "0").
            addResource("de/da/service/data/TblItem.hbm.xml").

            sFactory = config.buildSessionFactory();
        } catch (Throwable ex) {
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex.toString());
        }
    }

    return sFactory;
}
4

1 に答える 1

0

サービス プラグインの Buddy-Policy を尊重しませんでした。追加する必要がありました

Eclipse-RegisterBuddy: 'name-of-plugin-with-hibernate-jars'

私のサービスプラグインのマニフェストに。Hibernates Classloader は、xml マッピング ファイルを見つけるようになりました。

于 2013-02-06T10:01:03.923 に答える