I am trying to do a LEFT JOIN FETCH
to load a lazy loaded some data, but I am getting the following error.
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
I have searched everywhere online to see what I am doing incorrectly, but I don’t see what I am doing differently (other than my id not being a primitive type).
Here is what I have
@Entity @Setter @Getter @Table(name = "foo_definition") public class FooDefinition implements Serializable { @EmbeddedId private FooId fooId; ... }
Key
@Embeddable @Setter @Getter @NoArgsConstructor @AllArgsConstructor public class FooId implements Serializable { @Column(name = "fooId") private String id; }
Repo
@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, ... );
I have also tried message around with the query and the passed in type, e.g.
@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);
But none of these work as well (different errors)
What am I doing wrong?
Advertisement
Answer
In the end I had to do two things:
- replaced the complex key type of
FooId
with just aString
- replaced my
JoinTable
mapping withJoinColumn
, for myOneToMany
relation of some fields in myFooDefinition
class