How to populate DB with my JPA entities in IntelliJ

Is there a way in IntelliJ to create tables in the database from my entity classes? I mean no ER diagram. The IDE allows me to create entities from the DB, but not vice versa. I used netbeans and it just allows you to add objects to your persistense.xml and select a mode (drop and create, create, etc.), but I cannot find these options in IntelliJ. I set up a DB connection and it works, it just doesn't let me populate it with entities.

Here's my persistence.xml from NetBeans (works great)

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
  <persistence-unit name="ClubPU2" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>baseclub.entidades.Actividad</class>
    <class>baseclub.entidades.Comercio</class>
    <class>baseclub.entidades.Contacto</class>
    <class>baseclub.entidades.Cuota</class>
    <class>baseclub.entidades.DatosInstitucionales</class>
    <class>baseclub.entidades.DatosPersonales</class>
    <class>baseclub.entidades.Descuento</class>
    <class>baseclub.entidades.Identificacion</class>
    <class>baseclub.entidades.Miembro</class>
    <class>baseclub.entidades.NotaEntrada</class>
    <class>baseclub.entidades.Participacion</class>
    <class>baseclub.entidades.Rol</class>
    <class>baseclub.entidades.Secretaria</class>
    <class>baseclub.entidades.Sesion</class>
    <class>baseclub.entidades.Tutor</class>
    <class>baseclub.entidades.Ubicacion</class>
    <class>baseclub.entidades.Usuario</class>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
      <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/club_universitario?zeroDateTimeBehavior=convertToNull"/>
      <property name="javax.persistence.jdbc.password" value="XXXXXX"/>
      <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
      <property name="javax.persistence.jdbc.user" value="club"/>
      <property name="javax.persistence.schema-generation.database.action" value="create"/>
    </properties>
  </persistence-unit>
</persistence>

      

And here is persistence.xml from IntelliJ:

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">

    <persistence-unit name="persistenceUnit">

    </persistence-unit>
</persistence>

      

+3


source to share


1 answer


Is there any specific reason why IntelliJ wants to create a database?

if you chose Hibernate as ORM you can simply add the following code to your persistence.xml:



 <property name="hibernate.hbm2ddl.auto" value="update" />

      

Start the application server, deploy the application and create the database.

0


source







All Articles