具有多个数据库供应商支持的 Java/Maven/JPA/Hibernate 构建的最佳方法?

发布于 2024-09-01 16:08:44 字数 1111 浏览 10 评论 0原文

我有一个使用单个数据库的企业应用程序,但该应用程序需要支持 mysqloraclesql*server 作为安装选项。

为了尝试保持可移植,我们使用JPA注释Hibernate作为实现。我们还为每个正在运行的开发数据库提供了一个测试台实例。

该应用程序在Maven中构建得很好,我已经使用了hibernate3-maven-plugin,并且可以为给定的数据库方言自动生成DDL。

解决这个问题的最佳方法是什么,以便个人开发人员可以轻松地针对所有三个数据库进行测试,并且我们基于 Hudson 的 CI 服务器可以正确构建内容。

更具体地说:

  1. 我认为 只会生成一个架构文件,但显然它会连接到实时数据库并尝试创建架构 。有没有办法让这个只需为每个数据库方言创建模式文件而无需连接到数据库?

  2. 如果hibernate3-maven-plugin坚持实际创建数据库模式,有没有办法让它删除数据库并在创建模式之前重新创建它?

  3. 我认为每个开发人员(和 Hudson 构建机器)都应该在每个数据库服务器上拥有自己独立的数据库。这是典型的吗?

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

  5. hibernate3-maven-plugin 中有一个 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦在深巷 2024-09-08 16:08:44

1)有没有办法让它只为每个数据库方言创建模式文件而不连接到数据库?

export 设置为false。像这样的事情:

<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)如果 hibernate3-maven-plug 坚持实际创建数据库模式,有没有办法让它在创建模式之前删除数据库并重新创建它?

见上文。但为了以防万一,将 update 设置为 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)我认为每个开发人员(和 hudson 构建机器)应该在每个数据库服务器上拥有自己单独的数据库。这是典型的吗?

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

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

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

5) hibernate3-maven-plugin 中有一个 hbm2doc 目标。运行三次似乎有点过分了...我相信每个数据库的结果几乎是相同的。

我不习惯这个工具,但我想输出可能会有一些小小的变化(例如主键生成)。我将为每个数据库生成架构文档,但仅在发布时生成(当然不需要在每次构建时运行该文档)。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文