java - Spring Boot + Hibernate + Mysql 如何生成java类

标签 java hibernate maven

如何从 hibernate 插件生成 java 类?

我尝试过这样的在线指南

How to configure maven hbm2hbmxml and hbm2java to run one after the other in mvn clean install

但我无法生成它们。

最佳答案

pom.xml

<plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>hibernate3-maven-plugin</artifactId>
                <version>2.2</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>hbm2java</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <components>
                        <component>
                            <name>hbm2java</name>
                            <implementation>configuration</implementation>
                            <outputDirectory>target/generated-sources</outputDirectory>
                        </component>
                    </components>
                    <componentProperties>
                        <goal>hbm2java</goal>
                        <revengfile>/src/main/resources/model.reveng.xml</revengfile>
                        <configurationfile>/src/main/resources/hibernate.cfg.xml</configurationfile>
                        <drop>true</drop>
                        <jdk5>true</jdk5>

                    </componentProperties>
                </configuration>
            </plugin>

model.reveng.xml

<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >


<hibernate-reverse-engineering>
<schema-selection match-schema = "my_db" />
</hibernate-reverse-engineering>

hibernate.cfg.xml

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <!-- Database connection settings -->
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/my_db</property>
        <property name="hibernate.connection.username">user</property>
        <property name="hibernate.connection.password">pass</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>

        </session-factory>
</hibernate-configuration>

构建成功,但目标文件夹中没有类。

关于java - Spring Boot + Hibernate + Mysql 如何生成java类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49135901/

相关文章:

java - 线程中的异常 "AWT-EventQueue-0"java.lang.ArrayIndexOutOfBoundsException : 10 for Inventory

java - 在单个类上 hibernate 不同类型的一对一关系

java - DB2 中的 JDBC 和 Hibernate 错误 : Connection authorization failure occurred | SQL Error: -99999, SQLState: 42505

hibernate - java.lang.NoSuchMethodError : javax/persistence/spi/PersistenceUnitInfo. getValidationMode()Ljavax/persistence/ValidationMode

java - 如何仅在我的 war 中包含依赖项?

java - 使用rest进行 Elasticsearch 查询

java - 在 dropwizard 0.7.0 中使用 CORS header 过滤器

java - 从终端运行 java 项目时没有这样的文件

java - IllegalArgumentException : At least one JPA metamodel must be present

java - 如何在 URLClassLoader 中加载存储在应用程序资源中的 JAR