首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >maven hbm2ddl的简单设置

maven hbm2ddl的简单设置
EN

Stack Overflow用户
提问于 2010-09-10 00:31:40
回答 1查看 2.3K关注 0票数 1

我正在设置maven以获取带注释的java类并生成一些DDL,这些DDL会根据数据库的不同而有所不同。有没有更好的方法来做这件事?看起来我应该能够过滤hbm2ddl插件的输入(作为管道的一部分),而不是告诉它对资源过滤的输出进行操作(然后我必须从我的最终jar中过滤出来)。

我正在过滤我的hibernate.cfg.xml文件,根据本地开发人员的设置替换环境属性:

代码语言:javascript
复制
  <build>
    <filters>
      <filter>${user.home}/datamodel-build.properties</filter>
    </filters>
    <resources><resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
    </resource></resources>
  </build>

然后对输出运行hbm2ddl

代码语言:javascript
复制
<plugin>
 <groupId>org.codehaus.mojo</groupId>
 <artifactId>hibernate3-maven-plugin</artifactId>
  ...
 <configuration>
   <componentProperties>
   <configurationfile>target/classes/com/myOrg/datamodel/hibernate.cfg.xml</configurationfile>
</plugin>

然后我必须从我的生产jar中过滤出hibernate.cfg.xml,因为我不想发布任何与我的内部开发环境相关的东西。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-01-05 00:03:47

我也有同样的问题,下面是我是如何解决它的。我使用一个单独的database.properties文件来保存连接细节,并且我不过滤任何XML文件。

这个单独的database.properties文件会被过滤掉,但是因为它是位于/src/main/test中的一个测试资源,所以它不会被放入最终的工件中。然后我告诉hbm2ddl在哪里可以找到它,如下所示:

代码语言:javascript
复制
            <configuration>
                <components>
                    <component>
                        <name>hbm2ddl</name>
                        <implementation>jpaconfiguration</implementation>
                    </component>
                </components>
                <componentProperties>
                    <propertyfile>src/test/resources/database.properties</propertyfile>
                    <!-- Gives the name of the persistence unit as defined in persistence.xml -->
                    <persistenceunit>myapp-core</persistenceunit>
                    <!-- Tells the plugin to send the output to a file -->
                    <outputfilename>create-${database.vendor}-schema.sql</outputfilename>
                    <!-- Pretty Format SQL Code -->
                    <format>true</format>
                    <!-- Do not create tables automatically - other plug-ins will handle that -->
                    <export>false</export>
                    <!-- Do not print the DDL to the console -->
                    <console>false</console>
                </componentProperties>
            </configuration>

希望它能帮上忙。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3678562

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档