Why is my schema.ddl empty after hibernate3-maven-plugin?

This is the project directory structure (used by maven2):

pom.xml
/src
  /main
    /java
      Abc.java
    /resources
      hibernate.cfg.xml
      database.properties
      /META-INF
        persistence.xml
  /test
    /java
      AbcTest.java
    /resources
      database.properties

This content is hibernate.cfg.xml:

<hibernate-configuration>
  <session-factory name="java:hibernate/SessionFactory">
    <property name="hibernate.archive.autodetection">true</property>
  </session-factory>
</hibernate-configuration>

This is what I have in persistence.xml:

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

And this is my Abc.javafile:

import javax.persistence.*;
@Entity
public class Abc {
  @Id private int id;
}

After starting mvn clean hibernate3:hbm2ddlI get this output:

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

The file is schema.ddlcreated and it is empty. What for? And besides, what is wrong in my configuration files? Because when I try to run unit tests with PersistenceContextinjections, they fail with NullPointerException. There seem to be some problems with the configuration. Unable to find any manual online ...

PS. There are two problems, I have already found them. The first one (the additional prefix must be removed):

<property name="archive.autodetection">true</property>

. mvn hibernate3:hbm2ddl , ( .class ). . Java?

+3
2

, . ( )

. .

Java?

(, , , .. compile, ).

, Hibernate3 Maven Plugin, , hbm.xml. hibernate3:hbm2ddl process-resources .

XML compile (process-classes ), hibernate3:hbm2ddl.

, compile :

mvn compile hibernate3:hbm2ddl

- hibernate3:hbm2ddl , . process-classes:

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

process-classes, :

mvn process-classes
+2

, DOT- hibernate.cfg.xml . , .

0

Source: https://habr.com/ru/post/1766806/


All Articles