java - 如何通过 Hibernate 逆向工程使用 Hibernate Tools 生成 "Single DB"的模型代码

标签 java mysql hibernate hibernate-tools

我通过JBoss Tools > Hibernate Tools使用Hibernate逆向工程来生成模型类。

在那里,当我添加 Hibernate 配置并运行它/重建它时,它会列出所有数据库,尽管我在 hibernate.cfg.xml 的 hibernate.connection.url 中只提到了一个数据库。 例如:jdbc:mysql://localhost:3306/booksdb。

hibernate.cfg.xml

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration SYSTEM
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/booksdb</property>
        <property name="hibernate.connection.username">xxxx</property>
        <property name="hibernate.connection.password">xxxx</property>
    </session-factory>
</hibernate-configuration>

enter image description here

然后,当我生成实体代码时,它还会扫描所有其他数据库表以生成所有实体代码。有时它会受到不同数据库中某些重复表的影响。

问题: 如何对 hibernate.connection.url 中提到的单个数据库执行此操作?

Hibernate 代码生成配置 > 主要 enter image description here

Hibernate 代码生成配置 > 导出器 enter image description here

hibernate 版本:5.4

MySQL版本信息

  • innodb_version:5.7.26
  • 协议(protocol)版本:10
  • 版本:5.7.26-0ubuntu0.18.04.1
  • 版本注释:(Ubuntu)
  • 版本编译机器:x86_64
  • version_compile_os:Linux

最佳答案

在此屏幕中,转到 reveng.xml 附近的设置。它会要求您创建一个 xml,从那里您可以排除不需要的数据库。

In this screen

<hibernate-reverse-engineering>
    <table-filter match-name=".*" exclude="true" match-catalog="YOUR_DATABASE_NAME" />
</hibernate-reverse-engineering>

关于java - 如何通过 Hibernate 逆向工程使用 Hibernate Tools 生成 "Single DB"的模型代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57019319/

相关文章:

java - Spring AOP 表达式已执行但不应该执行

mysql - 帮助从 MySQL 触发器中删除别名

spring - 在@Transactional 中的事务期间提交

java - Hibernate 事务管理器性能问题

java - 如何阻止 Eclipse 对函数加下划线?

java - 在 Android 中使用 JCIFS

java - Log4j 配置 : how to use environment variable in yaml configuration file log4j2. yaml

MYSQL根据列字符串将值拆分为多列

用于复制 MySQL 数据库(包括其 View )的 PHP 脚本?

hibernate - 如何查询以二进制形式存储在数据库中的 UUID(JPA/Hibernate/MySQL)