我正在使用以下模型类:
@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
1条答案
按热度按时间ws51t4hk1#
尝试将下面一行添加到application.properties文件
spring.jpa.hibernate.ddl-auto=update
中