具有多个数据库供应商支持的 Java/Maven/JPA/Hibernate 构建的最佳方法?
我有一个使用单个数据库的企业应用程序,但该应用程序需要支持 mysql、oracle 和 sql*server 作为安装选项。
为了尝试保持可移植,我们使用JPA注释和Hibernate作为实现。我们还为每个正在运行的开发数据库提供了一个测试台实例。
该应用程序在Maven中构建得很好,我已经使用了hibernate3-maven-plugin,并且可以为给定的数据库方言自动生成DDL。
解决这个问题的最佳方法是什么,以便个人开发人员可以轻松地针对所有三个数据库进行测试,并且我们基于 Hudson 的 CI 服务器可以正确构建内容。
更具体地说:
我认为 hibernate3-maven-plugin 只会生成一个架构文件,但显然它会连接到实时数据库并尝试创建架构 。有没有办法让这个只需为每个数据库方言创建模式文件而无需连接到数据库?
如果hibernate3-maven-plugin坚持实际创建数据库模式,有没有办法让它删除数据库并在创建模式之前重新创建它?
我认为每个开发人员(和 Hudson 构建机器)都应该在每个数据库服务器上拥有自己独立的数据库。这是典型的吗?
开发人员是否必须为每个数据库供应商运行 Maven 三次...一次?如果是这样,我如何合并构建机器上的结果?
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:
I thought the hbm2ddl goal in the hibernate3-maven-plugin 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?
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?
I am thinking that each developer (and the Hudson build machine) should have their own separate database on each database server. Is this typical?
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?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将
export
设置为false
。像这样的事情:见上文。但为了以防万一,将
update
设置为true
:是的,我认为这是一种最佳实践(请参阅每个开发人员使用一个数据库实例 )。
是的,很可能,我会为每个数据库使用配置文件。在构建机器上,我将构建一个矩阵项目。
我不习惯这个工具,但我想输出可能会有一些小小的变化(例如主键生成)。我将为每个数据库生成架构文档,但仅在发布时生成(当然不需要在每次构建时运行该文档)。
Set
export
tofalse
. Something like this:See above. But just in case, for this set
update
totrue
: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).