【问题标题】:PSQLException: ERROR: operator does not exist: bigint = character varyingPSQLException:错误:运算符不存在:bigint = 字符变化
【发布时间】:2021-11-12 04:51:16
【问题描述】:

我正在尝试执行LEFT JOIN FETCH 来加载延迟加载的一些数据,但出现以下错误。

org.postgresql.util.PSQLException: ERROR: operator does not exist: bigint = character varying
  Hint: No operator matches the given name and argument types. You might need to add explicit type casts.
  Position: 726

我在网上到处搜索,看看我做错了什么,但我看不出我做错了什么(除了我的 id 不是原始类型)。

这就是我所拥有的

@Entity
@Setter
@Getter
@Table(name = "foo_definition")
public class FooDefinition implements Serializable {

  @EmbeddedId
  private FooId fooId;
  ...
}

@Embeddable
@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class FooId implements Serializable {
  @Column(name = "fooId")
  private String id;

}

回购

@Repository
public interface FooDefinitionRepository extends CrudRepository<FooDefinition, FooId> {

    @Query("SELECT c FROM FooDefinition c LEFT JOIN FETCH c.bundles WHERE c.fooId = :fooId")
    FooDefinition findByIdAndFetchBundlesEagerly(@Param("fooId") FooId fooId);
}

数据库

CREATE TABLE foo_definition (
    foo_id VARCHAR(50) NOT NULL PRIMARY KEY,
    ...
);

我也尝试过使用查询和传入类型的消息,例如

@Query("SELECT c FROM FooDefinition c LEFT JOIN FETCH c.bundles WHERE c.fooId.id = :fooId")
FooDefinition findByIdAndFetchBundlesEagerly(@Param("fooId") FooId fooId);

@Query("SELECT c FROM FooDefinition c LEFT JOIN FETCH c.bundles WHERE c.fooId.id = :fooId")
FooDefinition findByIdAndFetchBundlesEagerly(@Param("fooId") String fooId);

@Query("SELECT c FROM FooDefinition c LEFT JOIN FETCH c.bundles WHERE c.fooId = :fooId")
FooDefinition findByIdAndFetchBundlesEagerly(@Param("fooId") String fooId);

但这些都不起作用(不同的错误)

我做错了什么?

【问题讨论】:

    标签: java postgresql jpa


    【解决方案1】:

    最后我不得不做两件事:

    • String 替换了FooId 的复杂键类型
    • JoinColumn 替换了我的JoinTable 映射,用于我的OneToManyFooDefinition 类中某些字段的关系

    【讨论】:

      猜你喜欢
      • 2021-12-09
      • 2016-04-16
      • 1970-01-01
      • 1970-01-01
      • 2012-07-02
      • 2021-05-02
      • 2018-05-05
      • 2019-07-03
      • 2012-05-19
      相关资源
      最近更新 更多