spring-data-jpa org.postgresql.util.PSQLException:错误:关系“public.[table_name]”不存在

u59ebvdq  于 2022-11-10  发布在  Spring
关注(0)|答案(1)|浏览(130)

我正在使用以下模型类:

@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
}

然后在下面的接口和控制器中创建相应的db记录:

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);
}

我还在www.example.com文件中声明了我的模式application.properties

spring.jpa.properties.hibernate.default_schema=public

出现以下错误:

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

ws51t4hk1#

尝试将下面一行添加到application.properties文件spring.jpa.hibernate.ddl-auto=update

相关问题