2011-06-02 123 views
0

我們用Axis2框架(遺留系統)開發Web服務。使用jdbc它工作正常,但我需要使用它與休眠。 我試圖2點的方法: Axis2與Hibernate的集成(不包括Spring)

  • (內側AAR)我把hibernate.cfg

    1. (外AAR)我把冬眠* .jar文件到EARContent/lib和的hibernate.cfg.xml到WEB-ING /類.XML到AAR/META-INF /,並添加到service.xml的參數 <parameter name="ServiceTCCL">composite</parameter>

    在第一種情況下我不能在我失去了第二種情況的hibernate.cfg.xml達到 java.lang.RuntimeException: java.lang.RuntimeException: org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml

    訪問JNDII似乎失去了容器寬(jboss)jndi上下文。
    java.lang.RuntimeException: javax.naming.NameNotFoundException: UserTransaction not bound

    感謝

  • 回答

    0

    其實,我固定下面的代碼這個問題從我的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); 
    

    所以,我用的hibernate.cfg.xml staing在我的WebContent/WEB- INF /類以及EAR中的所有庫。