我正在尝试做一个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);
}
DB
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);
但是这些都不能正常工作(不同的错误)
我做错了什么?
最后我不得不做两件事:
- 用
String
代替 - 用
JoinColumn
代替了我的JoinTable
映射,因为我的FooDefinition
类中一些字段的OneToMany
关系
FooId
的复杂密钥类型