java - 将 HAR hibernate 存档迁移到 JBoss 7

标签 java mysql hibernate jboss

我正在将打包为 HAR hibernate 存档的应用程序从 JBoss AS5 迁移到 AS7。我有很多问题,而且我知道要成功迁移我的应用程序我必须面对很多障碍。我不介意自己研究一些东西 - 但在这一点上我不太确定什么是可能的,或者我应该采取的方向并且会很感激任何指示或评论。

我知道 JBoss AS7 不支持 HAR hibernate 存档 - 所以我必须进行一些更改才能使其正常工作。我的应用程序需要 hibernate3,我将其作为依赖项包含在内。我的 HAR 结构如下

HAR
|
|-com
|  |-business classes
|     |-*class files and *hbm.xml files
|
|-META-INF
   |-hibernate.xml

我的 hibernate.xml 文件看起来像

<hibernate-configuration xmlns="urn:jboss:hibernate-deployer:1.0">

   <session-factory name="java:/hibernate/SessionFactory" bean="jboss.har:service=Hibernate">
      <property name="datasourceName">java:/MySqlDS</property>
      <property name="dialect">org.hibernate.dialect.MySQLDialect</property>

 <!-- <property name="sessionFactoryInterceptor">org.jboss.test.hibernate.SimpleInterceptor</property> -->
 <!-- <property name="hbm2ddlAuto">create</property> -->
      <depends>jboss:service=Naming</depends>
      <depends>jboss:service=TransactionManager</depends>
   </session-factory>

</hibernate-configuration>

我们在 HAR 中使用 *hbm.xml 文件来定义实体,而不是更新样式的 hibernate 注释。我有几个问题:

-有没有一种方法可以将我的 HAR 打包为 JAR 并在 AS7 中使用它,而不必经历重写我的业务类以使用注释定义实体而不是使用 *hbm.xml 文件的麻烦?
-如果没有,是否有关于将代码转换为使用 hibernate 注释和 persistence.xml 的指南?我不介意做研究,但现在我不确定我应该研究什么。

最佳答案

JBoss 7 中不再存在 HAR 文件。事实上,甚至 ServiceMBeanSupport 也不存在了。一种可能性是使用某种机制来创建 SessionFactory 并将其注入(inject) JNDI。另一种可能性是“使用和不使用”新的 JPA api。 “使用”是指在 persistence.xml 文件中定义 Hibernate 配置并使用可用的映射检测功能。这将允许通过添加 META-INF/persistence.xml 文件将 .har 简单地重命名为 .jar,而无需在某处的长列表中对所有映射和类进行硬编码。 “不使用”是指初始化 JPA 但使用旧的 SessionFactory,因为当旧的 API 运行良好时没有理由更改为新的 API。 然而,另一个问题是 JBoss 7 与 Hibernate 4 捆绑在一起,迁移可能并不简单。然而,仍然有可能在您的应用程序中捆绑低至 3.5 的 Hibernate。这是 persistence.xml:

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
        version="2.0">
  <persistence-unit name="X">
    <description>X</description>
    <jta-data-source>java:/XOracleDS</jta-data-source>
    <properties>
    	<!-- This tells JBoss to use Hibernate 3 (as low as 3.5) bundled into the application  -->
        <property name="jboss.as.jpa.providerModule" value="hibernate3-bundled" />
        <!--<property name="jboss.as.jpa.managed" value="false"/>-->
        <!-- This will bind the session factory to JNDI as we require -->
        <property name="hibernate.session_factory_name" value="java:/hibernate/XOracleSessionFactory"/>
        <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
        <!-- This is one of the trickiest parts as Hibernate 3.5 does not has a RegionFactory and we must use the one from ehcache to bridge the gap -->
        <property name="hibernate.cache.region.factory_class" value="net.sf.ehcache.hibernate.EhCacheRegionFactory"/>
        <!-- very important to allow same names as in JBoss 4 -->
        <property name="hibernate.cache.region_prefix" value=""/>
        <property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.SingletonEhCacheProvider"/>
        <!-- This will make use of JBoss managed transactions. The factory is already present in JNDI -->
        <property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.JTATransactionFactory"/>
        <property name="hibernate.jdbc.batch_size" value="20"/>
        <property name="hibernate.show_sql" value="false"/>
     	<property name="hibernate.format_sql" value="false"/>
     	<property name="hibernate.cache.use_query_cache" value="true"/>
     	<property name="hibernate.cache.use_second_level_cache" value="true"/>
    </properties>
  </persistence-unit>
</persistence>

关于java - 将 HAR hibernate 存档迁移到 JBoss 7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7099422/

相关文章:

java - 如何在 thymeleaf 中传递字符串中的参数

java - nifi 禁用 Controller 服务休息 api 调用失败

mysql - 跨多个表搜索

mysql - 通过 phpmyadmin 在 MySQL 中填充表的最快方法

mysql - 是否可以在自引用表中对分层数据使用约束?

java - Dropwizard hibernate 1.0.0

java - 如何解决 java.math.BigInteger 无法转换为 java.lang.Integer

java - 将 Web 应用程序项目从 eclipse 独立移动到 tomcat

hibernate - AbstractTransactionalJUnit4SpringContextTests

java - Spring Maven War 项目未部署到 Tomcat 服务器