TSSK
TSSK

Reputation: 209

org.postgresql.util.PSQLException: ERROR: relation "public.[table_name]" does not exist

I am using the following model classes:

@Entity
@Table(name = "TableA")
public class TableA {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(nullable = false, name="Id")
    private BigInteger id;
    
    @OneToOne
    @JoinColumn(name = "Id", referencedColumnName = "Id")
    private TableB tableB;
    
    //Setters Getters
}



@Entity
@Table(name = "TableB")
public class TableB {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(nullable = false, name="Id")
    private BigInteger id;
    
    //Setters Getters
}

Then the following interface and controller to create the corresponding db records:

public interface TableARepository extends CrudRepository<TableA, BigInteger>{}

@Transactional(rollbackFor = Exception.class)
@PostMapping(value="/CreateTableA") 
public void createTableA(@RequestParam String something){
    TableB tableB = new TableB();
    TableA tableA = new TableA();
    tableA.setTableB(tableB);
    
    TableARepository.save(tableA);
}


I have also declared my schema at the application.properties file

spring.jpa.properties.hibernate.default_schema=public

I get the following error:

org.postgresql.util.PSQLException: ERROR: relation "public.tableA" does not exist

Upvotes: 1

Views: 665

Answers (1)

Sumit
Sumit

Reputation: 407

try adding below line to your application.properties file spring.jpa.hibernate.ddl-auto=update

Upvotes: 1

Related Questions