3

Is there a way in IntelliJ to create tables in a database from my entity classes? I mean without ER diagram. The IDE allows me to create entities from the DB, but not the other way around. I used to use netbeans and it just lets you add entities to your persistense.xml and select mode (drop and create, create, etc), but I can't find these options in IntelliJ. I have configures de DB connection and it works, it just doesn't allow me to populate it with my entities.

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

<?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's 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>
user3817446
  • 111
  • 1
  • 4

1 Answers1

0

Is there any particular reason you want IntelliJ to create the database?

if you have selected Hibernate as ORM , you can simply add in your persistence.xml the following code:

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

Start your application server, deploy your app and the database will be created.

fotis
  • 145
  • 1
  • 7