Java 为什么我的schema.ddl在hibernate3 maven插件之后是空的?

Java 为什么我的schema.ddl在hibernate3 maven插件之后是空的?,java,hibernate,maven-2,Java,Hibernate,Maven 2,这是项目的目录结构(使用maven2): 这是hibernate.cfg.xml的内容: <hibernate-configuration> <session-factory name="java:hibernate/SessionFactory"> <property name="hibernate.archive.autodetection">true</property> </session-factory> &l

这是项目的目录结构(使用maven2):

这是hibernate.cfg.xml的内容:

<hibernate-configuration>
  <session-factory name="java:hibernate/SessionFactory">
    <property name="hibernate.archive.autodetection">true</property>
  </session-factory>
</hibernate-configuration>
<persistence>
  <persistence-unit name="abc">
    <jta-data-source>java:/abcDS</jta-data-source>
    <properties>
      <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
    </properties>
  </persistence-unit>
</persistence>
这是我的
Abc.java
文件:

import javax.persistence.*;
@Entity
public class Abc {
  @Id private int id;
}
运行
mvn clean hibernate3:hbm2ddl后,我得到以下输出:

18:45:55,770  INFO org.hibernate.tool.hbm2ddl.SchemaExport - writing 
generated schema to file: ../target/hibernate3/sql/schema.ddl
18:45:55,770  INFO org.hibernate.tool.hbm2ddl.SchemaExport - schema export complete
[INFO] ————————————————————————————————————
[INFO] BUILD SUCCESSFUL
文件
schema.ddl
已创建,且为空。为什么?除此之外,我的配置文件有什么问题?因为当我尝试使用
PersistenceContext
注入运行单元测试时,它们会因
NullPointerException
而失败。看起来配置中有一些问题。联机找不到任何手册

PS.有两个问题,我已经发现了。第一个在此处(应删除额外的前缀):

true
第二个更有趣。编译后运行
mvn hibernate3:hbm2ddl
时,它可以工作(因为它有
.class
文件可以使用)。否则,架构为空。。如何指导这个插件预先编译java类

有两个问题,我已经发现了。第一个在这里(应该删除额外的前缀)

的确如此。所以我跳过这个

如何指导这个插件预先编译java类

不可能(但另一种方法是,我们将看到,在编译后运行插件)

事实上,Hibernate3 Maven插件早于注释,最初设计用于处理
hbm.xml
映射文件。这就是为什么在执行自身之前调用生命周期阶段
流程资源的执行

当使用注释而不是XML文件进行映射时,目标确实必须在
编译
阶段之后运行(该阶段将是一个自然候选阶段),但这不是
hibernate3:hbm2ddl
的当前行为

因此,在调用目标之前,您必须运行
compile

mvn compile hibernate3:hbm2ddl
另一个选项是在构建生命周期上绑定
hibernate3:hbm2ddl
,例如在
进程类上:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>hibernate3-maven-plugin</artifactId>
        <version>2.2</version>
        <executions>
          <execution>
            <phase>process-classes</phase><!-- compile would also work -->
            <goals>
              <goal>hbm2ddl</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  ...
</project>

要修复此问题,请在其映射配置中将DTO注释类添加到hibernate.cfg.xml。这解决了问题,并立即对我起作用,生成了数据库的完整架构。

不适用于我,我尝试了两种方法。。。schema.ddl始终为空
mvn compile hibernate3:hbm2ddl
<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>hibernate3-maven-plugin</artifactId>
        <version>2.2</version>
        <executions>
          <execution>
            <phase>process-classes</phase><!-- compile would also work -->
            <goals>
              <goal>hbm2ddl</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  ...
</project>
mvn process-classes