namalfernandolk
namalfernandolk

Reputation: 9134

How to generate model code for "Single DB" using Hibernate Tools through Hibernate Reverse Engineering

I use the Hibernate Reverse Engineering through JBoss Tools > Hibernate Tools to generate Model Classes.

There, when I add the Hibernate Configuration and Run it / Rebuild It, it list all the DBs although I mention only one DB in the hibernate.cfg.xml's hibernate.connection.url. eg : 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

Then when I generate the entities code it scans all other Database tables also to generate the entity codes for all. Sometimes it impact by some duplicated tables in different DBs.

Question : How to do this for single database mentioned in the hibernate.connection.url?

Hibernate Code Generation Configurations > Main enter image description here

Hibernate Code Generation Configurations > Exporters enter image description here

Hibernate version : 5.4

MySQL version Info

Upvotes: 0

Views: 603

Answers (1)

cookiemonster
cookiemonster

Reputation: 1

In this screen go to setup near reveng.xml. It will ask you to create a xml, from there you'll be able to exclude the databases you don't want.

In this screen

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

Upvotes: 0

Related Questions