[英]PSQLException: ERROR: column does not exist
I have following entities:我有以下实体:
@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;
}
and和
@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;
}
When im trying to get Nomenclature with JPARepository getById(id) method im getting org.postgresql.util.PSQLException: ERROR: column version0_.version_id does not exist
当我尝试使用 JPARepository getById(id) 方法获取命名法时,我正在获取
org.postgresql.util.PSQLException: ERROR: column version0_.version_id does not exist
It feels like the problem is around Hibernate Naming Strategies but i cant solve it.感觉问题出在 Hibernate 命名策略附近,但我无法解决。
Is there any other way to let Hibernate know which column should it use to join tables?有没有其他方法可以让 Hibernate 知道它应该使用哪一列来连接表?
Don't use @JoinTable
, the table is the same as the entity you are referencing.不要使用
@JoinTable
,该表与您引用的实体相同。 You just have to specify the @JoinColumn
, hibernate will look for the column in the table referenced by the entity you are mapping the list to, NomenclatureVersion
:您只需指定
@JoinColumn
, hibernate 将在表中查找您将列表映射到的实体所引用的列NomenclatureVersion
:
@OneToMany
@JoinColumn(name="nomenclature_id")
private List<NomenclatureVersion> version;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.