PSQLException: ERROR: column does not exist
PSQLException: ERROR: column does not exist
我有以下实体:
@Entity
@Getter
@Setter
@Table(name = "nomenclature", schema = "public")
public class Nomenclature implements Serializable {
@Id
@Column(name = "id")
private Long id;
@Column(name = "name")
private String name;
@OneToMany
@JoinTable(name="nomenclature_versions",
joinColumns= @JoinColumn(name="nomenclature_id", referencedColumnName="id"))
private List<NomenclatureVersion> version;
}
和
@Entity
@Setter
@Getter
@Table(name = "nomenclature_versions", schema = "public")
@NoArgsConstructor
public class NomenclatureVersion implements Serializable {
@Id
@Generated(GenerationTime.INSERT)
@Column(name = "id")
private Long id;
@Column(name = "nomenclature_id")
private Long nomenclatureId;
@Column(name = "user_id")
private Long userId;
@Column(name = "creation_date")
private LocalDateTime creationDate;
@Column(name = "puls_code")
private String pulsCode;
@Column(name = "pic_url")
private String picUrl;
@Column(name = "current")
private boolean current;
}
当我尝试使用 JPARepository getById(id) 方法获取 Nomenclature 时,我得到 org.postgresql.util.PSQLException: ERROR: column version0_.version_id does not exist
感觉问题出在 Hibernate Naming Strategies 上,但我无法解决。
有没有其他方法让 Hibernate 知道应该使用哪一列来连接表?
不要使用 @JoinTable
,table 与您引用的实体相同。您只需指定 @JoinColumn
,hibernate 将在 table 中查找您将列表映射到的实体引用的列,NomenclatureVersion
:
@OneToMany
@JoinColumn(name="nomenclature_id")
private List<NomenclatureVersion> version;
我有以下实体:
@Entity
@Getter
@Setter
@Table(name = "nomenclature", schema = "public")
public class Nomenclature implements Serializable {
@Id
@Column(name = "id")
private Long id;
@Column(name = "name")
private String name;
@OneToMany
@JoinTable(name="nomenclature_versions",
joinColumns= @JoinColumn(name="nomenclature_id", referencedColumnName="id"))
private List<NomenclatureVersion> version;
}
和
@Entity
@Setter
@Getter
@Table(name = "nomenclature_versions", schema = "public")
@NoArgsConstructor
public class NomenclatureVersion implements Serializable {
@Id
@Generated(GenerationTime.INSERT)
@Column(name = "id")
private Long id;
@Column(name = "nomenclature_id")
private Long nomenclatureId;
@Column(name = "user_id")
private Long userId;
@Column(name = "creation_date")
private LocalDateTime creationDate;
@Column(name = "puls_code")
private String pulsCode;
@Column(name = "pic_url")
private String picUrl;
@Column(name = "current")
private boolean current;
}
当我尝试使用 JPARepository getById(id) 方法获取 Nomenclature 时,我得到 org.postgresql.util.PSQLException: ERROR: column version0_.version_id does not exist
感觉问题出在 Hibernate Naming Strategies 上,但我无法解决。
有没有其他方法让 Hibernate 知道应该使用哪一列来连接表?
不要使用 @JoinTable
,table 与您引用的实体相同。您只需指定 @JoinColumn
,hibernate 将在 table 中查找您将列表映射到的实体引用的列,NomenclatureVersion
:
@OneToMany
@JoinColumn(name="nomenclature_id")
private List<NomenclatureVersion> version;