我正在使用Hibernate进入Eclipse RCP应用程序。我为hibernate映射创建了一个“服务”插件 - daos等。为了测试,我在这个插件中创建了一个“Main”类/方法。 “Main”执行HibernateUtil.initSessionFactory();
,然后针对所有映射对数据库进行一些查询。它工作正常。
当我从另一个eclipse插件执行相同的方法HibernateUtil.initSessionFactory();
时,例如“ui”我收到了:
java.lang.ExceptionInInitializerError: org.hibernate.MappingNotFoundException: 资源:未找到de / da / service / data / TblItem.hbm.xml
包含映射时的异常:
addResource( “DE / DA /服务/数据/ 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;
}
答案 0 :(得分:0)
我不尊重服务插件的好友政策。我需要添加
Eclipse-RegisterBuddy:'name-of-plugin-with-hibernate-jars'
到我的服务插件的清单。 Hibernates Classloader现在将找到xml映射文件。