【发布时间】: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