英文:
Eclipse Hibernate.cfg.xml is linking "sys" database from MySQL
问题
使用Hibernate连接到MySQL数据库时,在Eclipse中,还会显示与MySQL sys数据库的连接!以下是我使用的内容:
- Ubuntu 18.04.5 LTS(桌面版)
- Eclipse 2020-6(4.16.0)带有JBoss Tools、Hibernate-Tools插件。
- MySQL Ver 8.0.21用于Linux x86_64(MySQL社区服务器 - GPL)
注意:这是一个本地桌面项目,我正在按照教程进行工作。以后我不会在MySQL中使用root/admin权限。
以下是完整的hibernate.cfg.xml内容:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">admin</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/bookstoredb?serverTimezone=UTC</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
</session-factory>
</hibernate-configuration>
我是否误解了?按照给定的情况,连接URL难道不应该只连接到bookstoredb吗?为什么还连接到了“sys”?
当使用工具将数据库表反向生成Java类时,问题变得更加严重。我不仅得到了bookstoredb表的Java类,还得到了sys数据库中的每个表的Java类。而且,正如大家所知,sys数据库中有很多表。
如何取消链接到sys数据库?或者如何设置以不首先链接到它?
英文:
When I use Hibernate to connect to a MySQL database, bookstoredb, in Eclipse, a connection to the MySQL sys database also shows up!
I'm using the following:
- Ubuntu 18.04.5 LTS (desktop)
- Eclipse 2020-6 (4.16.0) w/JBoss Tools, Hibernate-Tools plugin.
- MySQL Ver 8.0.21 for Linux on x86_64 (MySQL Community Server - GPL)
Note: this is a local desktop project, I am working through a tutorial. I will NOT be using root/admin with MySQL down the road.
Following is the complete hibernate.cfg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">admin</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/bookstoredb?serverTimezone=UTC</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
</session-factory>
</hibernate-configuration>
Am I misunderstanding, shouldn't the connection.url, as given, ONLY connect to bookstoredb? Why is "sys" connecting also?
This becomes even more of a problem when using the tool to reverse-engineer the database tables into java classes. I'm getting not only the bookstoredb tables as java classes but every table in the sys database as well. And there are a lot of them, as I am sure folks well know.
How do I unlink the sys database? Or set things up so I don't link to it in the first place?
答案1
得分: 2
我猜sys是你的MySQL Workbench中的默认模式。
转到你的MySQL Workbench并删除这个模式,因为它正在从你的本地服务器导入所有的模式。
或
自定义:打开你的工作空间(Eclipse(屏幕顶部的“运行”选项卡->Hibernate代码生成)->转到Hibernate代码生成(->点击主要->revenge.xml->选择新建->选择文件夹->配置表过滤器->(1)选择要选择的数据库->导入所有表格->应用->运行。
现在你可以在你选择的位置看到所有的表格。
如果你想要定制导出,你也可以在上面的(1)步骤之后执行。
英文:
I guess sys is the default schema in your MySQL workbench.
Go to your Mysql workbench and drop the schema/because it is importing all the schemas from your local server.
or
Custom :- Open your workspace(eclipse("run" tab on top of screen->hibernate code genration) -> Go to hibernate code generation( -> click main-> revenge.xml->select new -> select folder-> configure table filter-> (1)select database you want to select-> import all table-> apply -> Run .
Now you can see all the tables in the location you have selected.
If you want to customer export you could also do so after (1) step above
答案2
得分: 1
对于那些遇到类似问题的人。Hibernate工具的反向工程会读取所有模式。因此,指定数据库是行不通的。因此,您需要一个自定义模式选择标签来指定您想要从中进行反向工程的数据库。可以通过创建一个名为hibernate.reveng.xml
的文件,并添加类似以下内容的内容来实现。其中,demo
是数据库的名称:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering SYSTEM "http://hibernate.org/dtd/hibernate-reverse-engineering-3.0.dtd">
<hibernate-reverse-engineering>
<schema-selection match-catalog="demo" match-schema=".*" match-table=".*"/>
</hibernate-reverse-engineering>
英文:
For those with a similar issue to this. Hibernate tools reverse engineering reads all schemas. Therefor specifying the database doesn't work. So you need a custom schema selection tag to specify which database you want reverse engineer from. This is done by creating a hibernate.reveng.xml
file and adding something like this where demo
is the name of the database
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering SYSTEM "http://hibernate.org/dtd/hibernate-reverse-engineering-3.0.dtd">
<hibernate-reverse-engineering>
<schema-selection match-catalog="demo" match-schema=".*" match-table=".*"/>
</hibernate-reverse-engineering>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论