【问题标题】:Spring Boot + Hibernate + Mysql how to generate class javaSpring Boot + Hibernate + Mysql如何生成java类
【发布时间】:2018-08-14 14:38:23
【问题描述】:

如何从hibernate插件生成java类?

我试过这样的在线指南

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

但我无法生成它们。

【问题讨论】:

  • 如果您发布更多信息会很好,例如 pom.xml 中的 hibernate3-maven-plugin 插件配置、your.reveng.xml、your.hibernate.properties,如果有例外。
  • 感谢这篇帖子stackoverflow.com/questions/7498174/…我解决了

标签: java hibernate maven


【解决方案1】:

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>

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

【讨论】:

  • RUN AS -> Maven 生成源
猜你喜欢
  • 2018-11-30
  • 2018-12-25
  • 2020-05-19
  • 2023-02-26
  • 2023-03-09
  • 1970-01-01
  • 1970-01-01
  • 2017-12-18
  • 2021-11-11
相关资源
最近更新 更多