对Java / Maven的/ JPA / Hibernate的建立与多个数据库供应商的支持最好的方法? [英] Best approach for Java/Maven/JPA/Hibernate build with multiple database vendor support?

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

问题描述

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

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

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

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

更具体地说:


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


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


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


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


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



解决方案

  

1)有没有办法让这个刚创建的每个数据库方言模式文件,无需连接到数据库?


设置导出。事情是这样的:

 <&插件GT;
  <的groupId方式>组织codehaus.mojo< /的groupId>
  <&的artifactId GT; Hibernate3的-Maven的插件< / artifactId的>
  <&版GT; 2.2< /版本>
  <结构>
    <成分>
      &所述;成分>
        <名称>&先得用hbm2ddl LT; /名称>
        <实施> annotationconfiguration< /执行>
      < /成分>
    < /成分>
    < componentProperties>
      <出口>假LT; /出口><! - 不导出到数据库 - >
      <&下降GT;真< /降>
      <&的ConfigurationFile GT;的src / main /资源/ hibernate.cfg.xml中< /&的ConfigurationFile GT;
      < outputfilename>&my_schema.ddl把LT; / outputfilename>
    < / componentProperties>
  < /结构>
< /插件>


  

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


见上面。但是为了以防万一,这组更新真正

 <&插件GT;
  <的groupId方式>组织codehaus.mojo< /的groupId>
  <&的artifactId GT; Hibernate3的-Maven的插件< / artifactId的>
  <&版GT; 2.2< /版本>
  <结构>
    <成分>
      &所述;成分>
        <名称>&先得用hbm2ddl LT; /名称>
        <实施> annotationconfiguration< /执行>
      < /成分>
    < /成分>
    < componentProperties>
      <出口>真< /出口>
      <更新和GT;真< /更新><! - 更新架构 - >
      <&下降GT;真< /降>
      <&的ConfigurationFile GT;的src / main /资源/ hibernate.cfg.xml中< /&的ConfigurationFile GT;
      < outputfilename>&my_schema.ddl把LT; / outputfilename>
    < / componentProperties>
  < /结构>
  <依赖和GT;
    <&依赖性GT;
      <&的groupId GT; org.apache.derby< /的groupId>
      <&的artifactId GT; derbyclient< / artifactId的>
      <&版GT; 10.5.3.0_1< /版本>
    < /依赖性>
  < /依赖和GT;
< /插件>


  

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


是的,我认为这是一个最佳实践(请参见使用每开发一个数据库实例)。


  

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


是的,很可能我会使用配置文件为每个数据库。在构建机器,我会建立一个矩阵项目


  

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


我不习惯这个工具,但我想有可能是在输出(例如与主键生成)一些小的变化。我会为每一个数据库,但仅释放时间架构文档(有当然是没有必要运行在每个版本)。

I have an enterprise application that uses a single database, but the application needs to support mysql, oracle, and sql*server as installation options.

To try to remain portable we are using JPA annotations with Hibernate as the implementation. We also have a test-bed instance of each database running for development.

The app is building nicely in Maven and I've played around with the hibernate3-maven-plugin and can auto-generate DDL for a given database dialect.

What is the best way to approach this so that individual developers can easily test against all three databases and our Hudson based CI server can build things properly.

More specifically:

  1. I thought the hbm2ddl goal in the would just generate a schema file, but apparently it connects to a live database and attempts to create the schema. Is there a way to have this just create the schema file for each database dialect without connecting to a database?

  2. If the hibernate3-maven-plugin insists on actually creating the database schema, is there a way to have it drop the database and recreate it before creating the schema?

  3. I am thinking that each developer (and the Hudson build machine) should have their own separate database on each database server. Is this typical?

  4. Will developers have to run Maven three times... once for each database vendor? If so, how do I merge the results on the build machine?

  5. There is a hbm2doc goal within hibernate3-maven-plugin. It seems overkill to run this three times... I gotta believe it'd be nearly identical for each database.

解决方案

1) Is there a way to have this just create the schema file for each database dialect without connecting to a database?

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>

2) If the hibernate3-maven-plug insists on actually creating the database schema, is there a way to have it drop the database and recreate it before creating the schema?

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>

3) I am thinking that each developer (and the hudson build machine) should have their own separate database on each database server. Is this typical?

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

4) Will developers have to run Maven three times...once for each database vendor? If so, how do I merge the results on the build machine?

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

5) There is a hbm2doc goal within hibernate3-maven-plugin. It seems overkill to run this three times...I gotta believe it'd be nearly identical for each database.

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的建立与多个数据库供应商的支持最好的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆