I am using hibernate with a function in PostgreSQL to update a record in the DB.
Following is the PostgreSQL function,
CREATE OR REPLACE FUNCTION updatesegment(segid bigint, segname text, segdesc text, segmeta text)
RETURNS void AS
$BODY$
BEGIN
UPDATE segment
SET
name = segname,
description = segdesc,
segmentmetadata = segmeta
WHERE
id = segid;
END;
$BODY$
LANGUAGE plpgsql;
In the java code I am invoking the function as below.
public int updateSegment(Long segmentId, String segName, String segDesc, String segMeta) {
SQLQuery query = (SQLQuery)sessionFactory.getCurrentSession().createSQLQuery("SELECT updatesegment(:segmentId, :segName, :segDesc, :segMeta)")
.setParameter("segmentId", segmentId)
.setParameter("segName", segName)
.setParameter("segDesc", segDesc)
.setParameter("segMeta", segMeta);
int rows = query.executeUpdate();
return rows;
}
When I call the updateSegment() java function above with the correct input parameters, the record in the DB gets updated as expected. But query.executeUpdate() is always returning 0 where as it should be returning 1.
What am I doing wrong and why isn't executeUpdate() returning 1?
Thanks in advance...!!!