Axis2和Hibernate集成(不含Spring)
我们使用Axis2框架(遗留系统)开发web服务。有了jdbc,它工作得很好,但我需要在hibernate中使用它。 我尝试了两种方法:Axis2和Hibernate集成(不含Spring),hibernate,axis2,Hibernate,Axis2,我们使用Axis2框架(遗留系统)开发web服务。有了jdbc,它工作得很好,但我需要在hibernate中使用它。 我尝试了两种方法: (aar之外)我将hibernate*.jars放在EARContent/lib中,将hibernate.cfg.xml放在WEB-ING/classes中 (在aar内部)我将hibernate.cfg.xml放入aar/META-INF/并添加到service.xml参数中 composite 在第一种情况下,我无法访问hibernate.cfg.xml
composite
java.lang.RuntimeException:java.lang.RuntimeException:org.hibernate.hibernateeException:无法解析配置:/hibernate.cfg.xml
在第二种情况下,我失去了对JNDII的访问,似乎失去了容器范围(jboss)的jndi上下文。java.lang.RuntimeException:javax.naming.NameNotFoundException:UserTransaction未绑定
谢谢事实上,我用hibernate SessionFactoryUtils中的以下代码修复了这个问题
// Create the initial SessionFactory from the default configuration files
log.debug("Initializing Hibernate");
AxisService axisService = MessageContext.getCurrentMessageContext().getAxisService();
ClassLoader serviceClassLoader = axisService.getClassLoader();
URL configURL = serviceClassLoader.getResource("hibernate.cfg.xml");
configuration = new AnnotationConfiguration();
// Use annotations: configuration = new AnnotationConfiguration();
// Read hibernate.cfg.xml (has to be present)
configuration.configure(configURL);
// Build and store (either in JNDI or static variable)
rebuildSessionFactory(configuration);
因此,我在WebContent/WEB-INF/classes中使用hibernate.cfg.xml,并在EAR中使用所有lib