用列表保存实体时如何解决错误
How to solve Error when save Entity with List
我有下一个实体(列表是在上次更新时添加的):
@Entity
@Table(name = "settings", schema = "notpublic")
public class Settings {
@Id
@GeneratedValue(generator = "settings_seq", strategy = GenerationType.SEQUENCE)
@SequenceGenerator(name = "settings_seq", sequenceName = "notpublic.settings_seq", schema = "notpublic", allocationSize = 1)
private Long id;
@Column
private String code;
@ElementCollection
@CollectionTable(name = "settings_bank", joinColumns = { @JoinColumn(name = "id") })
@Column(name = "bank_id")
private List<Long> bankIds;
和 liquibase 更新:
<createTable tableName="settings_bank" schemaName="notpublic">
<column name="id" type="BIGINT">
<constraints nullable="false"/>
</column>
<column name="bank_id" type="BIGINT">
<constraints nullable="false"/>
</column>
</createTable>
嗯,当我尝试保存实体时,我得到 rg.postgresql.util.PSQLException:错误:关系“settings_bank”不存在。我通过 pgAdmin 连接到数据库,并且创建了 table..
列出 bankIds- 很长,它没有连接到另一个实体。
我错过了什么以及如何解决它?
我解决了,忘了@CollectionTable中的schema
我有下一个实体(列表是在上次更新时添加的):
@Entity
@Table(name = "settings", schema = "notpublic")
public class Settings {
@Id
@GeneratedValue(generator = "settings_seq", strategy = GenerationType.SEQUENCE)
@SequenceGenerator(name = "settings_seq", sequenceName = "notpublic.settings_seq", schema = "notpublic", allocationSize = 1)
private Long id;
@Column
private String code;
@ElementCollection
@CollectionTable(name = "settings_bank", joinColumns = { @JoinColumn(name = "id") })
@Column(name = "bank_id")
private List<Long> bankIds;
和 liquibase 更新:
<createTable tableName="settings_bank" schemaName="notpublic">
<column name="id" type="BIGINT">
<constraints nullable="false"/>
</column>
<column name="bank_id" type="BIGINT">
<constraints nullable="false"/>
</column>
</createTable>
嗯,当我尝试保存实体时,我得到 rg.postgresql.util.PSQLException:错误:关系“settings_bank”不存在。我通过 pgAdmin 连接到数据库,并且创建了 table.. 列出 bankIds- 很长,它没有连接到另一个实体。 我错过了什么以及如何解决它?
我解决了,忘了@CollectionTable中的schema