user1191027
user1191027

Reputation:

Draw an ERD from Hibernate Mapping Files

I know it's possible to reverse engineer from the database into mapping files but does anyone know if it's possible to get hibernate to draw an ERD based on its own mapping files so that I can compare Hibernate's ERD with the Databases one?

Upvotes: 0

Views: 1933

Answers (3)

Michail Markou
Michail Markou

Reputation: 41

By Default hibernate creates MySql MyIsam Database which has internal connections instead of foreign keys so MySQL WORCKBENCH or VISUAL PARADIGM wont show ERD properly with connections make sure in application.properties inside resources to create this statement.

spring.jpa.hibernate.ddl-auto = update

spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL55Dialect

instead of

spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect

which creates MyISAM, watch for the double 5 this is the key here to change mode

Upvotes: 0

jeroen
jeroen

Reputation: 38

Yes, it's possible. As far as I know you can't do it directly from the mappings but instead you have to generate the database first.

What you have to do is simple:

  1. Create your database by your mapping
  2. Open (or download) MySQL Workbench
  3. Create a new Database Model Diagram
  4. Go to Database > Reverse Engineer and fill in your database details.
  5. Next steps should be easy for you

Upvotes: 0

user1191027
user1191027

Reputation:

I achieved this by using:

<property name="hibernate.hbm2ddl.auto">create-drop</property>

in my hibernate.cfg.xml

Then I used MySQL Workbench to reverse engineer an ERD from my database that was created by Hibernate.

Upvotes: 1

Related Questions