我有以下实体:
@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)方法获得命名时,我得到了org.postgresql.util.PSQLException: ERROR: column version0_.version_id does not exist
它感觉问题是围绕着Hibernate命名策略,但我无法解决它。
还有其他方法让Hibernate知道它应该使用哪一列来连接表吗?
发布于 2022-01-13 16:03:28
不要使用@JoinTable,该表与所引用的实体相同。只需指定@JoinColumn,hibernate将在表中查找由您将列表映射到的实体NomenclatureVersion引用的列:
@OneToMany
@JoinColumn(name="nomenclature_id")
private List<NomenclatureVersion> version;https://stackoverflow.com/questions/70699377
复制相似问题