-1

I'm getting the exception: org.postgresql.util.PSQLException relation doesn't exist when trying to persist a player object in the player table but I thought that the persist method is able to create the table

  em.getTransaction().begin();
  p = new Player(playerName);
  em.persist(p);
  em.getTransaction().commit();
Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
  • 1
    "*I thought that the persist method is able to create the table*" - No. You can configure the underlying implementation (e.g. [Hibernate](https://stackoverflow.com/questions/779479/reverse-engineer-ddl-from-jpa-entities/779629#779629)) to create the database schema for you at startup. I would, however, recommend using a separate tool, e.g. [flyway](https://flywaydb.org/) to create / migrate the database before application startup. – Turing85 Jan 03 '20 at 16:00
  • See https://stackoverflow.com/questions/32873844/how-to-automatic-create-table-in-jpa-persistence-xml-file – Renato Jan 03 '20 at 16:01
  • the generation schema action that i'm using is none so the above metioned solution is not right – hamza madridista Jan 03 '20 at 16:03

1 Answers1

1

JPA does not create the schema for you on-demand.

You can configure the underlying implementation (e.g. Hibernate) to create the database schema for you at application startup. I would, however, recommend using a separate tool, e.g. flyway to create / migrate the database before application startup. Synopsis being that the migration is under one's control, i.e. one can create / migrate the schema when one sees fit and the database is not automatically migrated at application startup. This process cann then be incoroporated and automated in a fully-fledged deployment process through, e.g., Jenkins.

Turing85
  • 18,217
  • 7
  • 33
  • 58