1
我第一次建立自己的項目時,我已經知道,如果它不停止做兩次事情,現在已經到了,我會變得瘋狂。我還沒有找到解決方案,或者我可能只是不知道如何搜索這個問題。Hibernate3 Maven插件配置錯誤?
我有一些hbm.xml文件在我的構建過程中得到處理。首先你可以看看我的pom.xml中應該這樣做的部分。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>generate-xml-files</id>
<phase>generate-resources</phase>
<goals>
<goal>hbm2cfgxml</goal>
</goals>
</execution>
<execution>
<id>generate-entities</id>
<phase>generate-resources</phase>
<goals>
<goal>hbm2java</goal>
</goals>
</execution>
<execution>
<id>generate-schema</id>
<phase>compile</phase>
<goals>
<goal>hbm2ddl</goal>
</goals>
</execution>
</executions>
<configuration>
<components>
<component>
<name>hbm2cfgxml</name>
<implementation>configuration</implementation>
<outputDirectory>target/classes</outputDirectory>
</component>
<component>
<name>hbm2java</name>
<implementation>configuration</implementation>
<outputDirectory>src/main/java</outputDirectory>
</component>
<component>
<name>hbm2ddl</name>
<implementation>configuration</implementation>
<outputDirectory>target/classes</outputDirectory>
</component>
</components>
<componentProperties>
<jdk5>true</jdk5>
<packagename>com.blazebit.web.cms.core.model</packagename>
<propertyfile>src/main/resources/database.properties</propertyfile>
<configurationfile>target/classes/hibernate.cfg.xml</configurationfile>
<!-- Tells the plugin to send the output to a file -->
<outputfilename>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>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.0.8</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>2.1_3</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>com.blazebit</groupId>
<artifactId>HibernateCfgBuilder</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>HibernateCfgBuilder</id>
<phase>generate-sources</phase>
<goals>
<goal>HibernateCfgBuilder</goal>
</goals>
</execution>
</executions>
<configuration>
<hbmXmlFilesDir>src/main/resources/com/blazebit/web/cms/core/model/</hbmXmlFilesDir>
<configFile>target/classes/hibernate.cfg.xml</configFile>
<packageName>com.blazebit.web.cms.core.model</packageName>
</configuration>
</plugin>
現在讓我來解釋一下這一切應該做什麼。
- 的第一件事是hbm2cfg我想,這應該創建一個hibernate.cfg.xml的
- 第二步是我自己的插件,它增加了路徑hbm.xml文件到的hibernate.cfg.xml(無法找到這個問題的其他解決方案)
- 第三步是調用:hbm2java其中生成Java文件到我的源代碼目錄
- 最後就是hbm2ddl應該在類路徑模型創建schema.sql文件
所以很簡單嗎?它甚至有效,但它似乎做了一些事情兩次甚至更多次,現在我的構建需要大約2分鐘,這是令人討厭的我:/ 任何人都可以給我一個小費,我可以改變這個步驟的工作?
我正在考慮編寫我自己的插件,它會執行這些步驟... –
在使用hbm2x生成文件時存在主要的性能問題。每個hbm.xml文件需要處理大約2秒鐘。我的最終解決方案是製作一個新的配置文件,用於調用目標,配置文件必須手動設置。我還刪除了hbm2cfg並擴展了我的插件來解析database.properties,因爲它的速度非常快! –