I have created a function as below :
CREATE OR REPLACE FUNCTION demo(ids SMALLINT[])
RETURNS TABLE (processkey bigint)
AS $$
BEGIN
RETURN QUERY SELECT b.processkey FROM your_table b WHERE id_column = ANY(ids);
END;
$$ LANGUAGE plpgsql;
In java repository class I create below method :
List<Object[]> getData(short[] ids) {
String strq="select * from demo(:ids)";
Query q=entitymanager.createNativeQuery(strq);
q.setParameter("ids",ids);
return q.getResultList();
}
In my controller :
short[] requestid= new short[]{1,2};
List<Object[]>response=repo.getData(requestid);
System.out.println(response);
But while executing this it gives error as Bytea cannot cast to smallint . I don't know why am getting this error
Error.o.h.e.SqlExecptionHelper-Error : cannot cast type bytea to smallint , position 26 , ExceptionHandlerExceptionResolver- javax.persistrnce.PersistenceException: SqlGrammerException : could not extract Resultset
getDatamethod. AlsocrrateNativeQuerylooks suspicious. Did you post actual code?