import javax.persistence.*;
@Table(name = "users")
@Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "userID")
private long userID;
}
@Table(name = "subscriptions")
@Entity
public class Subscription {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "subscriptionID")
private long subscriptionID;
@ManyToOne
@JoinColumn(name="userID")
private User user;
}
This code crashes:
Caused by: org.postgresql.util.PSQLException: ERROR: relation "subscriptions" does not exist
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL10Dialect spring.jpa.hibernate.ddl-auto=create-drop
spring.datasource.driver-class-name=org.postgresql.Driver
Code works for
import javax.persistence.*;
@Table(name = "users")
@Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "userID")
private long userID;
}
@Table(name = "subscriptions")
@Entity
public class Subscription {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "subscriptionID")
private long subscriptionID;
}
How can I fix it?
Just use spring.jpa.hibernate.ddl-auto=update
instead of create-drop
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.