I have a JpaRepository, with a native query in it:
@Query (value = "SELECT t.team_name FROM teams t " +
"WHERE (:teamcode IS NULL OR t.team_code = :teamcode) ",
nativeQuery = true)
List<Object[]> getTeamNames(@Param("teamcode") @Nullable String teamCode);
If I pass a non-null value, it works fine - the binding parameter type is VARCHAR. However, if I pass in a null parameter value, then the binding type is VARBINARY, and the query fails with the error:
SQL Error: 0, SQLState: 42883
ERROR: operator does not exist: character varying = bytea
Hint: No operator matches the given name and argument types. You might need to add explicit type casts.
Table:
CREATE TABLE teams (
team_id BIGINT NOT NULL,
team_code VARCHAR(24) NOT NULL,
team_name VARCHAR(200),
team_desc VARCHAR(2000),
)
Entity:
@Entity
@DynamicUpdate
@Getter
@Setter
@EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = false)
@Table(name = "teams", schema = "public")
public class Team extends BaseEntity
{
@Id
@Column(name = "team_id", nullable = false)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ent_generator")
@SequenceGenerator(name = "ent_generator", sequenceName = "entity_seq", allocationSize = 1)
private long teamId;
@EqualsAndHashCode.Include
@Basic
@Column(name = "team_code", length = 24)
private String teamCode;
@Basic
@Column(name = "team_name", length = 200)
private String teamName;
@Basic
@Column(name = "team_desc", length = 2000)
private String teamDescription;
}
How do I resolve this?