I try to create a relation between two tables in a Spring Boot Application.
I have the following Code:
@Entity
@Table(name = "account")
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Account {
@Id
@Column(name="ID", nullable = false, updatable = false)
@GeneratedValue(strategy=GenerationType.SEQUENCE)
private Long id;
@Column(name="NAME", nullable = false)
private String name;
@Column(name="client_id", nullable = false)
private Long clientId;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "client_id", insertable=false, updatable=false)
private Client client;
}
@Entity
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Client {
@Id
@Column(name="client_id", nullable = false, updatable = false)
@GeneratedValue(strategy=GenerationType.SEQUENCE)
private Long id;
@Column(name="NAME", nullable = false, unique = true)
private String name;
@OneToMany(mappedBy = "client", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
private List<Account> accounts;
}
I always get the error relation "account" does not exist. What could be wrong?
Caused by: org.postgresql.util.PSQLException: ERROR: relation "account" does not exist
2
Answers
Finally I could fix it changing:
to
in the application.properties file.
This exception is returned from the DB and converted into a java exception. In fact, you need to make sure that the table
account
exists in the DB.