使用Docker部署时无法在表中找到具有逻辑名称的列

时间:2019-07-19 10:09:29

标签: java spring postgresql hibernate docker

我有一个问题,只有在将应用程序部署到远程服务器(使用Docker)时才会发生。
在我的环境以及我的同事的环境中,以下代码有效,但是当我们尝试在远程服务器上进行部署时,会出现此休眠错误:无法在表Person中找到逻辑名称为id_region的列 >。

以下是Spring实体:

/** REGION **/
@Entity
public class Region {
    private Integer id;

    @Id
    @Column(name = "id")
    public Integer getId() {
        return id;
    }
}
/** PERSON **/
@Entity
public class Person {
    private Integer id;
    private String surname;
    private Region regionByIdRegion;
    private Collection<House> houses;

    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_PERSON")
    @SequenceGenerator(name = "SEQ_PERSON", 
        sequenceName = "SEQ_PERSON", 
        allocationSize = 1)
    public Integer getId() {
        return id;
    }

    @Basic
    @Column(name = "surname")
    public String getSurname() {
        return surname;
    }

    @ManyToOne
    @JoinColumn(name = "id_region", referencedColumnName = "id", nullable = false)
    public Region getRegionByIdRegion() {
        return regionByIdRegion;
    }

    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "PERSON_HOUSE", 
        joinColumns = {@JoinColumn(name = "ID_PERSON")}, 
        inverseJoinColumns = {@JoinColumn(name = "ID_HOUSE")})
    public Collection<House> getHouses() {
        return houses;
    }
}
/** HOUSE **/
@Entity
public class House {
    private Integer id;
    private String personName;
    private Region regionByIdRegion;
    private Person person;

    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_HOUSE")
    @SequenceGenerator(name = "SEQ_HOUSE", sequenceName = "SEQ_HOUSE", 
        allocationSize = 1)
    public Integer getId() {
        return id;
    }

    @Basic
    @Column(name = "person_name")
    public String getPersonName() {
        return personName;
    }

    @ManyToOne
    @JoinColumn(name = "id_region", referencedColumnName = "id", nullable = false)
    public Region getRegionByIdRegion() {
        return regionByIdRegion;
    }

    @ManyToOne
    @JoinColumn(name = "person_name", referencedColumnName = "surname", 
        insertable = false, updatable = false)
    @JoinColumn(name = "id_region", referencedColumnName = "id_region", 
        insertable = false, updatable = false)
    public House getPerson() {
        return person;
    }
}

问题位于House实体的getter getPerson()处。 person_name 字段不是外键,但它引用了Person。目标是获得具有以下内容的实体Person:
house.person_name = person.surname和house.id_region = person.id_region。

我们尝试将 @JoinColumn(name =“ id_region”,referencedColumnName =“ id_region”,insertable = false,可更新= false)替换为 @Where(clause =“ id_region = id_region “)。没有更多的休眠错误,但是我们没有得到好的实体。我认为这是因为两个id_region字段都在House表上获取,所以始终都是如此。我找不到一种方法来更精确地标识每个字段,以使where子句像house.id_region = person.id_region。

就像我之前说的那样,由于错误无法在表Person中找到逻辑名称为id_region的列,此代码可在本地环境上运行,。有谁知道为什么?

0 个答案:

没有答案