Is there an option in intellij to generate tables from our classes (entities)

11 Views Asked by At

How to generate database tables from entity classes with jpa hibernate. Using the IntelliJ IDE.

Because I created my entities with the jpa annotations, I also created the data source and tested the connection. But I don't know what to do afterwards so that these classes are transformed into tables in my database

1

There are 1 best solutions below

0
Kurisuchan On

If you're also using Spring Boot, you can generate your tables using this spring property spring.jpa.hibernate.ddl-auto=update. But you need to understand that this option generates tables for you, though will not provide you the SQL code. It's usually ok for tests i guess.

Also make sure you have this dependency:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

If you don't use spring, there's a hibernate only version too.

<!-- In persistence.xml -->
<property name="hibernate.hbm2ddl.auto" value="update"/>

OR

<!-- In hibernate.cfg.xml -->
<property name="hibernate.hbm2ddl.auto">update</property>