relation doesnt exist when creating postgres database from spring












1















I want to automatically create postgres database schema on startup of spring application.

I'm manually creating an empty database from pgadmin and when I'm running my spring application for first time I get this error log:
full log



Basically main errors are:



org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table day_places drop constraint FKscp1fnpwfhy14rf7tiur81akl" via JDBC Statement
Caused by: org.postgresql.util.PSQLException: ERROR: relation "day_places" does not exist
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table forecast drop constraint FKetkl57pr3fjhsv16f54gbbtbw" via JDBC Statement
Caused by: org.postgresql.util.PSQLException: ERROR: relation "forecast" does not exist
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table forecast drop constraint FKqo2b7v7gs8cgevlnvi1n7evxs" via JDBC Statement

Caused by: org.postgresql.util.PSQLException: ERROR: relation "forecast" does not exist

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table forecasts_forecast drop constraint FK160711nhmaixbibipj9v6j57t" via JDBC Statement

Caused by: org.postgresql.util.PSQLException: ERROR: relation "forecasts_forecast" does not exist

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table forecasts_forecast drop constraint FKeuqqos8m3g9yffrahb4hy5up6" via JDBC Statement

Caused by: org.postgresql.util.PSQLException: ERROR: relation "forecasts_forecast" does not exist

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table nights_places drop constraint FKaptmwcetlole3dc41suixjhts" via JDBC Statement

Caused by: org.postgresql.util.PSQLException: ERROR: relation "nights_places" does not exist

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table nights_places drop constraint FKgpbig7892x68kjxtf4lfbid08" via JDBC Statement

Caused by: org.postgresql.util.PSQLException: ERROR: relation "nights_places" does not exist


As I notice the errors are only about fields of classes which I have annotated as @onetomany.

Even though these errors are displayed, the tables are still created and used as expected.
After first running, these errors are not displayed anymore, But I want to still solve these. So how to create these relations on startup? any help will be appreciated



package home.persistence.domain.model;

import javax.persistence.*;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.List;
@Entity
@XmlRootElement(name="day")
@Table(name = "day")
public class Day
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Long id;
private String phenomenon;
private String tempmax;
private String tempmin;
private String text;
@OneToMany(cascade = CascadeType.ALL)
private List<Place> places;

public List<Place> getPlaces() {
return places;
}
@XmlElement(name = "place")
public void setPlaces(List<Place> places) {
this.places = places;
}

public String getPhenomenon ()
{
return phenomenon;
}

public void setPhenomenon (String phenomenon)
{
this.phenomenon = phenomenon;
}

public String getTempmax ()
{
return tempmax;
}

public void setTempmax (String tempmax)
{
this.tempmax = tempmax;
}

public String getTempmin ()
{
return tempmin;
}

public void setTempmin (String tempmin)
{
this.tempmin = tempmin;
}

public String getText ()
{
return text;
}

public void setText (String text)
{
this.text = text;
}

@Override
public String toString()
{
return "ClassPojo [phenomenon = "+phenomenon+", tempmax =
"+tempmax+", tempmin = "+tempmin+", text = "+text+"]";
}
}


Forecast:



@Entity
@XmlRootElement(name="forecast")
@Table(name = "forecast")
public class Forecast

{
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
Long id;
@OneToOne(cascade = CascadeType.ALL)
private Night night;
@OneToOne(cascade = CascadeType.ALL)
private Day day;
@XmlAttribute(name = "date")
public String date;

public Long getId() {
return id;
}


public Night getNight ()
{
return night;
}

public void setNight (Night night)
{
this.night = night;
}

public Day getDay ()
{
return day;
}

public void setDay (Day day)
{
this.day = day;
}


public void setDate (String date)
{
this.date = date;
}

@Override
public String toString()
{
return "ClassPojo [night = "+night+", day = "+day+", date = "+date+"]";
}


}



Forecasts:



@Entity
@XmlRootElement(name="forecasts")
@Table(name = "forecasts")
public class Forecasts
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Long id;
@OneToMany(cascade = CascadeType.ALL)
private List<Forecast> forecast;

public List<Forecast> getForecast() {
return forecast;
}
@XmlElement(name = "forecast")
public void setForecast(List<Forecast> forecast) {
this.forecast = forecast;
}

public Long getId() {
return id;
}

@Override
public String toString()
{
return "ClassPojo [forecast = "+ forecast +"]";
}
}


Night:



@Entity
@XmlRootElement(name = "night")
@Table(name = "nights")
public class Night {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Long id;
private String phenomenon;
private String tempmax;
private String tempmin;
private String text;
@OneToMany(cascade = CascadeType.ALL)
private List<Place> places;

public List<Place> getPlaces() {
return places;
}
@XmlElement(name = "place")
public void setPlaces(List<Place> places) {
this.places = places;
}



public String getPhenomenon() {
return phenomenon;
}

public void setPhenomenon(String phenomenon) {
this.phenomenon = phenomenon;
}

public String getTempmax() {
return tempmax;
}

public void setTempmax(String tempmax) {
this.tempmax = tempmax;
}

public String getTempmin() {
return tempmin;
}

public void setTempmin(String tempmin) {
this.tempmin = tempmin;
}

public String getText() {
return text;
}

public void setText(String text) {
this.text = text;
}

@Override
public String toString() {
return "ClassPojo [phenomenon = " + phenomenon + ", tempmax = " + tempmax + ", tempmin = " + tempmin + ", text = " + text + "]";
}
}


Day:



@Entity
@XmlRootElement(name="day")
@Table(name = "day")
public class Day
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Long id;
private String phenomenon;
private String tempmax;
private String tempmin;
private String text;
@OneToMany(cascade = CascadeType.ALL)
private List<Place> places;

public List<Place> getPlaces() {
return places;
}
@XmlElement(name = "place")
public void setPlaces(List<Place> places) {
this.places = places;
}

public String getPhenomenon ()
{
return phenomenon;
}

public void setPhenomenon (String phenomenon)
{
this.phenomenon = phenomenon;
}

public String getTempmax ()
{
return tempmax;
}

public void setTempmax (String tempmax)
{
this.tempmax = tempmax;
}

public String getTempmin ()
{
return tempmin;
}

public void setTempmin (String tempmin)
{
this.tempmin = tempmin;
}

public String getText ()
{
return text;
}

public void setText (String text)
{
this.text = text;
}

@Override
public String toString()
{
return "ClassPojo [phenomenon = "+phenomenon+", tempmax = "+tempmax+", tempmin = "+tempmin+", text = "+text+"]";
}
}


Day:



@Entity
@XmlRootElement(name="place")
@Table(name = "place")
public class Place
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Long id;
private String phenomenon;
private String tempmin;
private String tempmax;
private String name;

public Long getId() {
return id;
}

public String getTempmax() {
return tempmax;
}

public void setTempmax(String tempmax) {
this.tempmax = tempmax;
}

public String getPhenomenon ()
{
return phenomenon;
}

public void setPhenomenon (String phenomenon)
{
this.phenomenon = phenomenon;
}

public String getTempmin ()
{
return tempmin;
}

public void setTempmin (String tempmin)
{
this.tempmin = tempmin;
}

public String getName ()
{
return name;
}

public void setName (String name)
{
this.name = name;
}

@Override
public String toString()
{
return "ClassPojo [phenomenon = "+phenomenon+", tempmin = "+tempmin+", name = "+name+"]";
}
}


application.properties



server.port=8090
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/database
spring.datasource.username=username
spring.datasource.password=password
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.generate-ddl=true
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false









share|improve this question



























    1















    I want to automatically create postgres database schema on startup of spring application.

    I'm manually creating an empty database from pgadmin and when I'm running my spring application for first time I get this error log:
    full log



    Basically main errors are:



    org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table day_places drop constraint FKscp1fnpwfhy14rf7tiur81akl" via JDBC Statement
    Caused by: org.postgresql.util.PSQLException: ERROR: relation "day_places" does not exist
    org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table forecast drop constraint FKetkl57pr3fjhsv16f54gbbtbw" via JDBC Statement
    Caused by: org.postgresql.util.PSQLException: ERROR: relation "forecast" does not exist
    org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table forecast drop constraint FKqo2b7v7gs8cgevlnvi1n7evxs" via JDBC Statement

    Caused by: org.postgresql.util.PSQLException: ERROR: relation "forecast" does not exist

    org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table forecasts_forecast drop constraint FK160711nhmaixbibipj9v6j57t" via JDBC Statement

    Caused by: org.postgresql.util.PSQLException: ERROR: relation "forecasts_forecast" does not exist

    org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table forecasts_forecast drop constraint FKeuqqos8m3g9yffrahb4hy5up6" via JDBC Statement

    Caused by: org.postgresql.util.PSQLException: ERROR: relation "forecasts_forecast" does not exist

    org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table nights_places drop constraint FKaptmwcetlole3dc41suixjhts" via JDBC Statement

    Caused by: org.postgresql.util.PSQLException: ERROR: relation "nights_places" does not exist

    org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table nights_places drop constraint FKgpbig7892x68kjxtf4lfbid08" via JDBC Statement

    Caused by: org.postgresql.util.PSQLException: ERROR: relation "nights_places" does not exist


    As I notice the errors are only about fields of classes which I have annotated as @onetomany.

    Even though these errors are displayed, the tables are still created and used as expected.
    After first running, these errors are not displayed anymore, But I want to still solve these. So how to create these relations on startup? any help will be appreciated



    package home.persistence.domain.model;

    import javax.persistence.*;
    import javax.xml.bind.annotation.XmlElement;
    import javax.xml.bind.annotation.XmlRootElement;
    import java.util.List;
    @Entity
    @XmlRootElement(name="day")
    @Table(name = "day")
    public class Day
    {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    Long id;
    private String phenomenon;
    private String tempmax;
    private String tempmin;
    private String text;
    @OneToMany(cascade = CascadeType.ALL)
    private List<Place> places;

    public List<Place> getPlaces() {
    return places;
    }
    @XmlElement(name = "place")
    public void setPlaces(List<Place> places) {
    this.places = places;
    }

    public String getPhenomenon ()
    {
    return phenomenon;
    }

    public void setPhenomenon (String phenomenon)
    {
    this.phenomenon = phenomenon;
    }

    public String getTempmax ()
    {
    return tempmax;
    }

    public void setTempmax (String tempmax)
    {
    this.tempmax = tempmax;
    }

    public String getTempmin ()
    {
    return tempmin;
    }

    public void setTempmin (String tempmin)
    {
    this.tempmin = tempmin;
    }

    public String getText ()
    {
    return text;
    }

    public void setText (String text)
    {
    this.text = text;
    }

    @Override
    public String toString()
    {
    return "ClassPojo [phenomenon = "+phenomenon+", tempmax =
    "+tempmax+", tempmin = "+tempmin+", text = "+text+"]";
    }
    }


    Forecast:



    @Entity
    @XmlRootElement(name="forecast")
    @Table(name = "forecast")
    public class Forecast

    {
    @Id @GeneratedValue(strategy = GenerationType.IDENTITY)
    Long id;
    @OneToOne(cascade = CascadeType.ALL)
    private Night night;
    @OneToOne(cascade = CascadeType.ALL)
    private Day day;
    @XmlAttribute(name = "date")
    public String date;

    public Long getId() {
    return id;
    }


    public Night getNight ()
    {
    return night;
    }

    public void setNight (Night night)
    {
    this.night = night;
    }

    public Day getDay ()
    {
    return day;
    }

    public void setDay (Day day)
    {
    this.day = day;
    }


    public void setDate (String date)
    {
    this.date = date;
    }

    @Override
    public String toString()
    {
    return "ClassPojo [night = "+night+", day = "+day+", date = "+date+"]";
    }


    }



    Forecasts:



    @Entity
    @XmlRootElement(name="forecasts")
    @Table(name = "forecasts")
    public class Forecasts
    {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    Long id;
    @OneToMany(cascade = CascadeType.ALL)
    private List<Forecast> forecast;

    public List<Forecast> getForecast() {
    return forecast;
    }
    @XmlElement(name = "forecast")
    public void setForecast(List<Forecast> forecast) {
    this.forecast = forecast;
    }

    public Long getId() {
    return id;
    }

    @Override
    public String toString()
    {
    return "ClassPojo [forecast = "+ forecast +"]";
    }
    }


    Night:



    @Entity
    @XmlRootElement(name = "night")
    @Table(name = "nights")
    public class Night {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    Long id;
    private String phenomenon;
    private String tempmax;
    private String tempmin;
    private String text;
    @OneToMany(cascade = CascadeType.ALL)
    private List<Place> places;

    public List<Place> getPlaces() {
    return places;
    }
    @XmlElement(name = "place")
    public void setPlaces(List<Place> places) {
    this.places = places;
    }



    public String getPhenomenon() {
    return phenomenon;
    }

    public void setPhenomenon(String phenomenon) {
    this.phenomenon = phenomenon;
    }

    public String getTempmax() {
    return tempmax;
    }

    public void setTempmax(String tempmax) {
    this.tempmax = tempmax;
    }

    public String getTempmin() {
    return tempmin;
    }

    public void setTempmin(String tempmin) {
    this.tempmin = tempmin;
    }

    public String getText() {
    return text;
    }

    public void setText(String text) {
    this.text = text;
    }

    @Override
    public String toString() {
    return "ClassPojo [phenomenon = " + phenomenon + ", tempmax = " + tempmax + ", tempmin = " + tempmin + ", text = " + text + "]";
    }
    }


    Day:



    @Entity
    @XmlRootElement(name="day")
    @Table(name = "day")
    public class Day
    {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    Long id;
    private String phenomenon;
    private String tempmax;
    private String tempmin;
    private String text;
    @OneToMany(cascade = CascadeType.ALL)
    private List<Place> places;

    public List<Place> getPlaces() {
    return places;
    }
    @XmlElement(name = "place")
    public void setPlaces(List<Place> places) {
    this.places = places;
    }

    public String getPhenomenon ()
    {
    return phenomenon;
    }

    public void setPhenomenon (String phenomenon)
    {
    this.phenomenon = phenomenon;
    }

    public String getTempmax ()
    {
    return tempmax;
    }

    public void setTempmax (String tempmax)
    {
    this.tempmax = tempmax;
    }

    public String getTempmin ()
    {
    return tempmin;
    }

    public void setTempmin (String tempmin)
    {
    this.tempmin = tempmin;
    }

    public String getText ()
    {
    return text;
    }

    public void setText (String text)
    {
    this.text = text;
    }

    @Override
    public String toString()
    {
    return "ClassPojo [phenomenon = "+phenomenon+", tempmax = "+tempmax+", tempmin = "+tempmin+", text = "+text+"]";
    }
    }


    Day:



    @Entity
    @XmlRootElement(name="place")
    @Table(name = "place")
    public class Place
    {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    Long id;
    private String phenomenon;
    private String tempmin;
    private String tempmax;
    private String name;

    public Long getId() {
    return id;
    }

    public String getTempmax() {
    return tempmax;
    }

    public void setTempmax(String tempmax) {
    this.tempmax = tempmax;
    }

    public String getPhenomenon ()
    {
    return phenomenon;
    }

    public void setPhenomenon (String phenomenon)
    {
    this.phenomenon = phenomenon;
    }

    public String getTempmin ()
    {
    return tempmin;
    }

    public void setTempmin (String tempmin)
    {
    this.tempmin = tempmin;
    }

    public String getName ()
    {
    return name;
    }

    public void setName (String name)
    {
    this.name = name;
    }

    @Override
    public String toString()
    {
    return "ClassPojo [phenomenon = "+phenomenon+", tempmin = "+tempmin+", name = "+name+"]";
    }
    }


    application.properties



    server.port=8090
    spring.datasource.driver-class-name=org.postgresql.Driver
    spring.datasource.url=jdbc:postgresql://localhost:5432/database
    spring.datasource.username=username
    spring.datasource.password=password
    spring.jpa.hibernate.ddl-auto=create-drop
    spring.jpa.generate-ddl=true
    spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
    spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false









    share|improve this question

























      1












      1








      1








      I want to automatically create postgres database schema on startup of spring application.

      I'm manually creating an empty database from pgadmin and when I'm running my spring application for first time I get this error log:
      full log



      Basically main errors are:



      org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table day_places drop constraint FKscp1fnpwfhy14rf7tiur81akl" via JDBC Statement
      Caused by: org.postgresql.util.PSQLException: ERROR: relation "day_places" does not exist
      org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table forecast drop constraint FKetkl57pr3fjhsv16f54gbbtbw" via JDBC Statement
      Caused by: org.postgresql.util.PSQLException: ERROR: relation "forecast" does not exist
      org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table forecast drop constraint FKqo2b7v7gs8cgevlnvi1n7evxs" via JDBC Statement

      Caused by: org.postgresql.util.PSQLException: ERROR: relation "forecast" does not exist

      org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table forecasts_forecast drop constraint FK160711nhmaixbibipj9v6j57t" via JDBC Statement

      Caused by: org.postgresql.util.PSQLException: ERROR: relation "forecasts_forecast" does not exist

      org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table forecasts_forecast drop constraint FKeuqqos8m3g9yffrahb4hy5up6" via JDBC Statement

      Caused by: org.postgresql.util.PSQLException: ERROR: relation "forecasts_forecast" does not exist

      org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table nights_places drop constraint FKaptmwcetlole3dc41suixjhts" via JDBC Statement

      Caused by: org.postgresql.util.PSQLException: ERROR: relation "nights_places" does not exist

      org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table nights_places drop constraint FKgpbig7892x68kjxtf4lfbid08" via JDBC Statement

      Caused by: org.postgresql.util.PSQLException: ERROR: relation "nights_places" does not exist


      As I notice the errors are only about fields of classes which I have annotated as @onetomany.

      Even though these errors are displayed, the tables are still created and used as expected.
      After first running, these errors are not displayed anymore, But I want to still solve these. So how to create these relations on startup? any help will be appreciated



      package home.persistence.domain.model;

      import javax.persistence.*;
      import javax.xml.bind.annotation.XmlElement;
      import javax.xml.bind.annotation.XmlRootElement;
      import java.util.List;
      @Entity
      @XmlRootElement(name="day")
      @Table(name = "day")
      public class Day
      {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      Long id;
      private String phenomenon;
      private String tempmax;
      private String tempmin;
      private String text;
      @OneToMany(cascade = CascadeType.ALL)
      private List<Place> places;

      public List<Place> getPlaces() {
      return places;
      }
      @XmlElement(name = "place")
      public void setPlaces(List<Place> places) {
      this.places = places;
      }

      public String getPhenomenon ()
      {
      return phenomenon;
      }

      public void setPhenomenon (String phenomenon)
      {
      this.phenomenon = phenomenon;
      }

      public String getTempmax ()
      {
      return tempmax;
      }

      public void setTempmax (String tempmax)
      {
      this.tempmax = tempmax;
      }

      public String getTempmin ()
      {
      return tempmin;
      }

      public void setTempmin (String tempmin)
      {
      this.tempmin = tempmin;
      }

      public String getText ()
      {
      return text;
      }

      public void setText (String text)
      {
      this.text = text;
      }

      @Override
      public String toString()
      {
      return "ClassPojo [phenomenon = "+phenomenon+", tempmax =
      "+tempmax+", tempmin = "+tempmin+", text = "+text+"]";
      }
      }


      Forecast:



      @Entity
      @XmlRootElement(name="forecast")
      @Table(name = "forecast")
      public class Forecast

      {
      @Id @GeneratedValue(strategy = GenerationType.IDENTITY)
      Long id;
      @OneToOne(cascade = CascadeType.ALL)
      private Night night;
      @OneToOne(cascade = CascadeType.ALL)
      private Day day;
      @XmlAttribute(name = "date")
      public String date;

      public Long getId() {
      return id;
      }


      public Night getNight ()
      {
      return night;
      }

      public void setNight (Night night)
      {
      this.night = night;
      }

      public Day getDay ()
      {
      return day;
      }

      public void setDay (Day day)
      {
      this.day = day;
      }


      public void setDate (String date)
      {
      this.date = date;
      }

      @Override
      public String toString()
      {
      return "ClassPojo [night = "+night+", day = "+day+", date = "+date+"]";
      }


      }



      Forecasts:



      @Entity
      @XmlRootElement(name="forecasts")
      @Table(name = "forecasts")
      public class Forecasts
      {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      Long id;
      @OneToMany(cascade = CascadeType.ALL)
      private List<Forecast> forecast;

      public List<Forecast> getForecast() {
      return forecast;
      }
      @XmlElement(name = "forecast")
      public void setForecast(List<Forecast> forecast) {
      this.forecast = forecast;
      }

      public Long getId() {
      return id;
      }

      @Override
      public String toString()
      {
      return "ClassPojo [forecast = "+ forecast +"]";
      }
      }


      Night:



      @Entity
      @XmlRootElement(name = "night")
      @Table(name = "nights")
      public class Night {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      Long id;
      private String phenomenon;
      private String tempmax;
      private String tempmin;
      private String text;
      @OneToMany(cascade = CascadeType.ALL)
      private List<Place> places;

      public List<Place> getPlaces() {
      return places;
      }
      @XmlElement(name = "place")
      public void setPlaces(List<Place> places) {
      this.places = places;
      }



      public String getPhenomenon() {
      return phenomenon;
      }

      public void setPhenomenon(String phenomenon) {
      this.phenomenon = phenomenon;
      }

      public String getTempmax() {
      return tempmax;
      }

      public void setTempmax(String tempmax) {
      this.tempmax = tempmax;
      }

      public String getTempmin() {
      return tempmin;
      }

      public void setTempmin(String tempmin) {
      this.tempmin = tempmin;
      }

      public String getText() {
      return text;
      }

      public void setText(String text) {
      this.text = text;
      }

      @Override
      public String toString() {
      return "ClassPojo [phenomenon = " + phenomenon + ", tempmax = " + tempmax + ", tempmin = " + tempmin + ", text = " + text + "]";
      }
      }


      Day:



      @Entity
      @XmlRootElement(name="day")
      @Table(name = "day")
      public class Day
      {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      Long id;
      private String phenomenon;
      private String tempmax;
      private String tempmin;
      private String text;
      @OneToMany(cascade = CascadeType.ALL)
      private List<Place> places;

      public List<Place> getPlaces() {
      return places;
      }
      @XmlElement(name = "place")
      public void setPlaces(List<Place> places) {
      this.places = places;
      }

      public String getPhenomenon ()
      {
      return phenomenon;
      }

      public void setPhenomenon (String phenomenon)
      {
      this.phenomenon = phenomenon;
      }

      public String getTempmax ()
      {
      return tempmax;
      }

      public void setTempmax (String tempmax)
      {
      this.tempmax = tempmax;
      }

      public String getTempmin ()
      {
      return tempmin;
      }

      public void setTempmin (String tempmin)
      {
      this.tempmin = tempmin;
      }

      public String getText ()
      {
      return text;
      }

      public void setText (String text)
      {
      this.text = text;
      }

      @Override
      public String toString()
      {
      return "ClassPojo [phenomenon = "+phenomenon+", tempmax = "+tempmax+", tempmin = "+tempmin+", text = "+text+"]";
      }
      }


      Day:



      @Entity
      @XmlRootElement(name="place")
      @Table(name = "place")
      public class Place
      {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      Long id;
      private String phenomenon;
      private String tempmin;
      private String tempmax;
      private String name;

      public Long getId() {
      return id;
      }

      public String getTempmax() {
      return tempmax;
      }

      public void setTempmax(String tempmax) {
      this.tempmax = tempmax;
      }

      public String getPhenomenon ()
      {
      return phenomenon;
      }

      public void setPhenomenon (String phenomenon)
      {
      this.phenomenon = phenomenon;
      }

      public String getTempmin ()
      {
      return tempmin;
      }

      public void setTempmin (String tempmin)
      {
      this.tempmin = tempmin;
      }

      public String getName ()
      {
      return name;
      }

      public void setName (String name)
      {
      this.name = name;
      }

      @Override
      public String toString()
      {
      return "ClassPojo [phenomenon = "+phenomenon+", tempmin = "+tempmin+", name = "+name+"]";
      }
      }


      application.properties



      server.port=8090
      spring.datasource.driver-class-name=org.postgresql.Driver
      spring.datasource.url=jdbc:postgresql://localhost:5432/database
      spring.datasource.username=username
      spring.datasource.password=password
      spring.jpa.hibernate.ddl-auto=create-drop
      spring.jpa.generate-ddl=true
      spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
      spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false









      share|improve this question














      I want to automatically create postgres database schema on startup of spring application.

      I'm manually creating an empty database from pgadmin and when I'm running my spring application for first time I get this error log:
      full log



      Basically main errors are:



      org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table day_places drop constraint FKscp1fnpwfhy14rf7tiur81akl" via JDBC Statement
      Caused by: org.postgresql.util.PSQLException: ERROR: relation "day_places" does not exist
      org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table forecast drop constraint FKetkl57pr3fjhsv16f54gbbtbw" via JDBC Statement
      Caused by: org.postgresql.util.PSQLException: ERROR: relation "forecast" does not exist
      org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table forecast drop constraint FKqo2b7v7gs8cgevlnvi1n7evxs" via JDBC Statement

      Caused by: org.postgresql.util.PSQLException: ERROR: relation "forecast" does not exist

      org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table forecasts_forecast drop constraint FK160711nhmaixbibipj9v6j57t" via JDBC Statement

      Caused by: org.postgresql.util.PSQLException: ERROR: relation "forecasts_forecast" does not exist

      org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table forecasts_forecast drop constraint FKeuqqos8m3g9yffrahb4hy5up6" via JDBC Statement

      Caused by: org.postgresql.util.PSQLException: ERROR: relation "forecasts_forecast" does not exist

      org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table nights_places drop constraint FKaptmwcetlole3dc41suixjhts" via JDBC Statement

      Caused by: org.postgresql.util.PSQLException: ERROR: relation "nights_places" does not exist

      org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table nights_places drop constraint FKgpbig7892x68kjxtf4lfbid08" via JDBC Statement

      Caused by: org.postgresql.util.PSQLException: ERROR: relation "nights_places" does not exist


      As I notice the errors are only about fields of classes which I have annotated as @onetomany.

      Even though these errors are displayed, the tables are still created and used as expected.
      After first running, these errors are not displayed anymore, But I want to still solve these. So how to create these relations on startup? any help will be appreciated



      package home.persistence.domain.model;

      import javax.persistence.*;
      import javax.xml.bind.annotation.XmlElement;
      import javax.xml.bind.annotation.XmlRootElement;
      import java.util.List;
      @Entity
      @XmlRootElement(name="day")
      @Table(name = "day")
      public class Day
      {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      Long id;
      private String phenomenon;
      private String tempmax;
      private String tempmin;
      private String text;
      @OneToMany(cascade = CascadeType.ALL)
      private List<Place> places;

      public List<Place> getPlaces() {
      return places;
      }
      @XmlElement(name = "place")
      public void setPlaces(List<Place> places) {
      this.places = places;
      }

      public String getPhenomenon ()
      {
      return phenomenon;
      }

      public void setPhenomenon (String phenomenon)
      {
      this.phenomenon = phenomenon;
      }

      public String getTempmax ()
      {
      return tempmax;
      }

      public void setTempmax (String tempmax)
      {
      this.tempmax = tempmax;
      }

      public String getTempmin ()
      {
      return tempmin;
      }

      public void setTempmin (String tempmin)
      {
      this.tempmin = tempmin;
      }

      public String getText ()
      {
      return text;
      }

      public void setText (String text)
      {
      this.text = text;
      }

      @Override
      public String toString()
      {
      return "ClassPojo [phenomenon = "+phenomenon+", tempmax =
      "+tempmax+", tempmin = "+tempmin+", text = "+text+"]";
      }
      }


      Forecast:



      @Entity
      @XmlRootElement(name="forecast")
      @Table(name = "forecast")
      public class Forecast

      {
      @Id @GeneratedValue(strategy = GenerationType.IDENTITY)
      Long id;
      @OneToOne(cascade = CascadeType.ALL)
      private Night night;
      @OneToOne(cascade = CascadeType.ALL)
      private Day day;
      @XmlAttribute(name = "date")
      public String date;

      public Long getId() {
      return id;
      }


      public Night getNight ()
      {
      return night;
      }

      public void setNight (Night night)
      {
      this.night = night;
      }

      public Day getDay ()
      {
      return day;
      }

      public void setDay (Day day)
      {
      this.day = day;
      }


      public void setDate (String date)
      {
      this.date = date;
      }

      @Override
      public String toString()
      {
      return "ClassPojo [night = "+night+", day = "+day+", date = "+date+"]";
      }


      }



      Forecasts:



      @Entity
      @XmlRootElement(name="forecasts")
      @Table(name = "forecasts")
      public class Forecasts
      {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      Long id;
      @OneToMany(cascade = CascadeType.ALL)
      private List<Forecast> forecast;

      public List<Forecast> getForecast() {
      return forecast;
      }
      @XmlElement(name = "forecast")
      public void setForecast(List<Forecast> forecast) {
      this.forecast = forecast;
      }

      public Long getId() {
      return id;
      }

      @Override
      public String toString()
      {
      return "ClassPojo [forecast = "+ forecast +"]";
      }
      }


      Night:



      @Entity
      @XmlRootElement(name = "night")
      @Table(name = "nights")
      public class Night {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      Long id;
      private String phenomenon;
      private String tempmax;
      private String tempmin;
      private String text;
      @OneToMany(cascade = CascadeType.ALL)
      private List<Place> places;

      public List<Place> getPlaces() {
      return places;
      }
      @XmlElement(name = "place")
      public void setPlaces(List<Place> places) {
      this.places = places;
      }



      public String getPhenomenon() {
      return phenomenon;
      }

      public void setPhenomenon(String phenomenon) {
      this.phenomenon = phenomenon;
      }

      public String getTempmax() {
      return tempmax;
      }

      public void setTempmax(String tempmax) {
      this.tempmax = tempmax;
      }

      public String getTempmin() {
      return tempmin;
      }

      public void setTempmin(String tempmin) {
      this.tempmin = tempmin;
      }

      public String getText() {
      return text;
      }

      public void setText(String text) {
      this.text = text;
      }

      @Override
      public String toString() {
      return "ClassPojo [phenomenon = " + phenomenon + ", tempmax = " + tempmax + ", tempmin = " + tempmin + ", text = " + text + "]";
      }
      }


      Day:



      @Entity
      @XmlRootElement(name="day")
      @Table(name = "day")
      public class Day
      {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      Long id;
      private String phenomenon;
      private String tempmax;
      private String tempmin;
      private String text;
      @OneToMany(cascade = CascadeType.ALL)
      private List<Place> places;

      public List<Place> getPlaces() {
      return places;
      }
      @XmlElement(name = "place")
      public void setPlaces(List<Place> places) {
      this.places = places;
      }

      public String getPhenomenon ()
      {
      return phenomenon;
      }

      public void setPhenomenon (String phenomenon)
      {
      this.phenomenon = phenomenon;
      }

      public String getTempmax ()
      {
      return tempmax;
      }

      public void setTempmax (String tempmax)
      {
      this.tempmax = tempmax;
      }

      public String getTempmin ()
      {
      return tempmin;
      }

      public void setTempmin (String tempmin)
      {
      this.tempmin = tempmin;
      }

      public String getText ()
      {
      return text;
      }

      public void setText (String text)
      {
      this.text = text;
      }

      @Override
      public String toString()
      {
      return "ClassPojo [phenomenon = "+phenomenon+", tempmax = "+tempmax+", tempmin = "+tempmin+", text = "+text+"]";
      }
      }


      Day:



      @Entity
      @XmlRootElement(name="place")
      @Table(name = "place")
      public class Place
      {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      Long id;
      private String phenomenon;
      private String tempmin;
      private String tempmax;
      private String name;

      public Long getId() {
      return id;
      }

      public String getTempmax() {
      return tempmax;
      }

      public void setTempmax(String tempmax) {
      this.tempmax = tempmax;
      }

      public String getPhenomenon ()
      {
      return phenomenon;
      }

      public void setPhenomenon (String phenomenon)
      {
      this.phenomenon = phenomenon;
      }

      public String getTempmin ()
      {
      return tempmin;
      }

      public void setTempmin (String tempmin)
      {
      this.tempmin = tempmin;
      }

      public String getName ()
      {
      return name;
      }

      public void setName (String name)
      {
      this.name = name;
      }

      @Override
      public String toString()
      {
      return "ClassPojo [phenomenon = "+phenomenon+", tempmin = "+tempmin+", name = "+name+"]";
      }
      }


      application.properties



      server.port=8090
      spring.datasource.driver-class-name=org.postgresql.Driver
      spring.datasource.url=jdbc:postgresql://localhost:5432/database
      spring.datasource.username=username
      spring.datasource.password=password
      spring.jpa.hibernate.ddl-auto=create-drop
      spring.jpa.generate-ddl=true
      spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
      spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false






      spring postgresql






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 21 '18 at 20:45









      giusha9giusha9

      558




      558
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53420219%2frelation-doesnt-exist-when-creating-postgres-database-from-spring%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53420219%2frelation-doesnt-exist-when-creating-postgres-database-from-spring%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

          SQL update select statement

          'app-layout' is not a known element: how to share Component with different Modules