本文介绍了对Java / Maven的/ JPA / Hibernate的建立与多个数据库供应商的支持最好的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用单个数据库的企业应用程序,但应用程序需要支持的的mysql 的Oracle SQL *服务器作为安装选项。

要尝试的保持便携的我们使用的 JPA注释休眠作为实施。我们也有运行发展的每个数据库的试验台实例。

该应用程序是很好的建设的Maven ,我已经用在 Hibernate3的-Maven的插件各地播放,可以自动生成DDL对于一个给定的数据库方言。

什么是解决这个使个人开发者可以轻松地测试对所有三个数据库和我们的哈德逊基于CI服务器可以正确地构建东西的最佳方式。

更具体地说:


  1. 我想在先得用hbm2ddl 在目标的只会生成模式文件,的但显然它连接到一个实时的数据库,并试图创建模式的。有没有一种方法能有这个的只是创建架构文件的每个数据库方言的没有的连接到数据库?


  2. 如果在 Hibernate3的-Maven的插件在实际创建数据库架构坚持,有没有办法把它删除数据库和创建架构之前重新创建它?


  3. 我想,每个开发人员(和哈得逊建造机)应有的每个数据库服务器上自己单独的数据库。这是典型的?


  4. 将开发人员必须为每个数据库供应商也运行了三次......一次?如果是这样,我怎么合并构建机器上的结果?


  5. 有一个 hbm2doc Hibernate3的-Maven的插件内的目标。这似乎矫枉过正跑了三次......我不得不相信这将会是每个数据库几乎相同。



解决方案

Set export to false. Something like this:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>hibernate3-maven-plugin</artifactId>
  <version>2.2</version>
  <configuration>
    <components>
      <component>
        <name>hbm2ddl</name>
        <implementation>annotationconfiguration</implementation>
      </component>
    </components>
    <componentProperties>
      <export>false</export><!-- do not export to the database -->
      <drop>true</drop>
      <configurationfile>src/main/resources/hibernate.cfg.xml</configurationfile>
      <outputfilename>my_schema.ddl</outputfilename>
    </componentProperties>
  </configuration>
</plugin>

See above. But just in case, for this set update to true:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>hibernate3-maven-plugin</artifactId>
  <version>2.2</version>
  <configuration>
    <components>
      <component>
        <name>hbm2ddl</name>
        <implementation>annotationconfiguration</implementation>
      </component>
    </components>
    <componentProperties>
      <export>true</export>
      <update>true</update><!-- update the schema -->
      <drop>true</drop>
      <configurationfile>src/main/resources/hibernate.cfg.xml</configurationfile>
      <outputfilename>my_schema.ddl</outputfilename>
    </componentProperties>
  </configuration>
  <dependencies>
    <dependency>
      <groupId>org.apache.derby</groupId>
      <artifactId>derbyclient</artifactId>
      <version>10.5.3.0_1</version>
    </dependency>
  </dependencies>
</plugin>

Yes, and I consider this as a best practices (see Use one database instance per developer).

Yes, very likely and I would use profiles for each database. On the build machine, I would build a matrix project.

I'm not used to this tool but I guess there might be some little variation in the output (e.g. with the primary key generation). I would generate the schema documentation for each database but at release time only (there is certainly no need to run that at each build).

这篇关于对Java / Maven的/ JPA / Hibernate的建立与多个数据库供应商的支持最好的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 04:42