Java 导致原因:org.postgresql.util.PSQLException:错误:列Performance3\u.app\u user\u internal\u user\u id不存在

Java 导致原因:org.postgresql.util.PSQLException:错误:列Performance3\u.app\u user\u internal\u user\u id不存在,java,spring-boot,jpa,jhipster,liquibase,Java,Spring Boot,Jpa,Jhipster,Liquibase,我有这个问题=> 2020-12-08 10:10:31.472 ERROR 7184 --- [ XNIO-1 task-4] c.f.timesheet.service.AppUserService : Exception in findOne() with cause = 'org.hibernate.exception.SQLGrammarException: could not extract ResultSet' and exception = 'could not ext

我有这个问题=>

2020-12-08 10:10:31.472 ERROR 7184 --- [  XNIO-1 task-4] c.f.timesheet.service.AppUserService     : Exception in findOne() with cause = 'org.hibernate.exception.SQLGrammarException: could not extract ResultSet' and exception = 'could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet'

Caused by: org.postgresql.util.PSQLException: ERROR: column performanc3_.app_user_internal_user_id does not exist
我想添加一个与appUser具有oneToMany关系的新实体。 我在stackoverflow上搜索了一些响应,但很多时候问题出在模式名上。 因此,我向每个实体添加了模式名称,但它仍然不起作用

也许问题就在我的要求里

这些实体是:

应用程序用户:

@Entity
@Table(name = "app_user", schema = "public")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class AppUser implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @Column(name = "internal_user_id", unique = true, nullable = false)
    private Long id;

    @Column(name = "phone")
    private String phone;

    @OneToOne(cascade = CascadeType.ALL)
    @MapsId
    private User internalUser;

    @ManyToMany
    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
    @JoinTable(
        name = "app_user_job",
        joinColumns = @JoinColumn(name = "internal_user_id"),
        inverseJoinColumns = @JoinColumn(name = "job_id", referencedColumnName = "id")
    )
    private Set<Job> jobs = new HashSet<>();

    @ManyToOne
    @JsonIgnoreProperties(value = "appUsers", allowSetters = true)
    private Company company;

    @OneToMany(mappedBy = "appUser",cascade = CascadeType.REMOVE)
    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
    private Set<Performance> performances = new HashSet<>();
以及请求:

 @Query(
        "select appUser from AppUser appUser " +
        "left join fetch appUser.jobs " +
        "left join appUser.performances " +
        " where appUser.id =:id"
    )
    Optional<AppUser> findOneWithEagerRelationships(@Param("id") Long id);
@Query(
“从appUser appUser中选择appUser”+
“左加入获取appUser.jobs”+
“左加入appUser.Performance”+
“其中appUser.id=:id”
)
可选findonewiteagerrationships(@Param(“id”)Long id);
还有liquibase xml:

应用程序用户:

<changeSet id="20201111182357-1" author="jhipster">
    <createTable tableName="app_user">
        <column name="internal_user_id" type="bigint">
            <constraints primaryKey="true" nullable="false"/>
        </column>

        <column name="phone" type="varchar(255)">

            <constraints nullable="true" />
        </column>
        <column name="company_id" type="bigint">
            <constraints nullable="true" />
        </column>
        <!-- jhipster-needle-liquibase-add-column - JHipster will add columns here -->
    </createTable>
</changeSet>
<changeSet id="20201111182357-1-relations" author="jhipster">

    <createTable tableName="app_user_job">
        <column name="job_id" type="bigint">
            <constraints nullable="false"/>
        </column>
        <column name="internal_user_id" type="bigint">
            <constraints nullable="false"/>
        </column>
    </createTable>
    <addPrimaryKey columnNames="internal_user_id, job_id" tableName="app_user_job"/>
    
</changeSet>

性能:

@Entity
@Table(name = "performance", schema = "public")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Performance implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
    @SequenceGenerator(name = "sequenceGenerator")
    private Long id;

    @NotNull
    @Min(value = 0)
    @Max(value = 16)
    @Column(name = "hours", nullable = false)
    private Integer hours;

    @NotNull
    @Column(name = "date", nullable = false)
    private LocalDate date;

    @ManyToOne
    @JsonIgnoreProperties(value = "performances_user", allowSetters = true)
    private AppUser appUser;

    @ManyToOne
    @JsonIgnoreProperties(value = "performances_job", allowSetters = true)
    private Job job;
    <changeSet id="20201202093141-1" author="jhipster">
    <createTable tableName="performance">
        <column name="id" type="bigint">
            <constraints primaryKey="true" nullable="false"/>
        </column>
        <column name="hours" type="integer">
            <constraints nullable="false" />
        </column>
        <column name="date" type="date">
            <constraints nullable="false" />
        </column>
        <column name="user_id" type="bigint">
            <constraints nullable="true" />
        </column>
        <column name="job_id" type="bigint">
            <constraints nullable="true" />
        </column>
        <!-- jhipster-needle-liquibase-add-column - JHipster will add columns here -->
    </createTable>
</changeSet>

以及他的限制

<changeSet id="20201202093141-2" author="jhipster">
    
    <addForeignKeyConstraint baseColumnNames="user_id"
                             baseTableName="performance"
                             constraintName="fk_performance_user_id"
                             referencedColumnNames="internal_user_id"
                             referencedTableName="app_user"/>

    <addForeignKeyConstraint baseColumnNames="job_id"
                             baseTableName="performance"
                             constraintName="fk_performance_job_id"
                             referencedColumnNames="id"
                             referencedTableName="job"/>

</changeSet>

谢谢

我找到了解决办法。
不知道为什么,但它正在搜索一个不存在的app\u user\u internal\u user\u id列。我将@JoinColumn(name=“user\u id”)添加到性能实体中,它可以正常工作。

您的
@id
列名为
internal\u user\u id
,关系为
appUser
,转换为
app\u user
。 因此Hibernate猜测
Performance.appUser
join列是
app\u user\u internal\u user\u id

命名策略的任务是在物理列名不明确时猜测物理列名

我猜您使用的是
SpringImplicitNamingStrategy
,它实现了
org.hibernate.boot.model.naming.ImplicitNamingStrategy
,值得阅读文档或这篇文章: