我通过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>
然后,当我生成实体代码时,它还会扫描所有其他数据库表以生成所有实体代码。有时它会受到不同数据库中某些重复表的影响。
问题: 如何对 hibernate.connection.url 中提到的单个数据库执行此操作?
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,从那里您可以排除不需要的数据库。
<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/