java - Spring data repository sends null as bytea to PostgreSQL database -


after switching mysql postgresql found out sql query (@query in spring data repository interface) not work anymore. issue caused null value being sent bytea , i'm getting following exception:

caused by: org.postgresql.util.psqlexception: error: operator not exist: bigint = bytea hint: no operator matches given name , argument type(s). might need add explicit type casts. 

repository @query:

public interface winerepository extends pagingandsortingrepository<wine, long> {     @query(value = "select * wine w (?1 null or w.id = ?1)", nativequery = true)     wine simpletest(long id); } 

simple test:

logger.warn("test1: {}", winerepository.simpletest(1l));    //ok logger.warn("test2: {}", winerepository.simpletest(null));  //psqlexception 

in real case have multiple parameters can null , prefer not checking them in java code sending them sql query. have checked questions here on stackoverflow found none answer spring data repository @query annotation.

what correct way of handling null values postgresql? or have hints how fix approach? thanks!

update: issue seems related nativequery = true, when value false, null values work expected. question whether possible make function nativequery enabled.

you trying check whether java null equal postgres null think not necessary. can rewrite following , avoid sending null simpletest function @ all.

@query(value = "select * wine w (w.id null or w.id = ?1)", nativequery = true) wine simpletest(long id); 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -