简体   繁体   中英

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

It feels like the problem is around Hibernate Naming Strategies but i cant solve it.

Is there any other way to let Hibernate know which column should it use to join tables?

Don't use @JoinTable , the table is the same as the entity you are referencing. 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 :

@OneToMany
@JoinColumn(name="nomenclature_id") 
private List<NomenclatureVersion> version;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM