我正在尝试调用执行更新的PL / pgSQL函数(语言sql,返回void)。我得到了这个例外:
Internal Exception: org.postgresql.util.PSQLException: A result was returned when none was expected.
的persistence.xml:
<named-native-query name="Clinic.deactivateByNotFoundInIncomingClinic">
<query>
<![CDATA[
select apply_incoming_clinic_deletions(?)
]]>
</query>
</named-native-query>
DAO:
public void deactivateByNotFoundInIncomingClinic(long clinicSystemId)
{
em.createNamedQuery("Clinic.deactivateByNotFoundInIncomingClinic")
.setParameter(1, clinicSystemId)
.executeUpdate();
}
帮助!
更新
在GlassFish 3.1.1上使用EclipeseLink通过PostgreSQL 9.0-801 JDBC 4驱动程序与PostgreSQL 9.0数据库通信。
答案 0 :(得分:2)
不确定这是从哪里来的。问题中缺少您的功能定义
但您可以尝试使用plpgsql
函数而不是sql
。声明为RETURNS void
时,它们的返回类型略有不同。考虑一下这个演示:
CREATE OR REPLACE FUNCTION f_sql()
RETURNS void AS
'UPDATE foo SET id = id+1 WHERE id = 34567'
LANGUAGE sql;
CREATE OR REPLACE FUNCTION f_plpgsql()
RETURNS void AS
$$
BEGIN
UPDATE foo SET id = id+1 WHERE id = 34567;
END;
$$ LANGUAGE plpgsql;
现在,VOID是虚构类型。虽然plpgsql函数实际上返回VOID,但SQL函数似乎返回NULL。我不确定自己为什么会这样。
db=# SELECT f_sql() IS NULL;
?column?
----------
t
db=# SELECT f_plpgsql() IS NULL;
?column?
----------
f
答案 1 :(得分:1)
将DAO代码更改为此工作:
public void deactivateByNotFoundInIncomingClinic(long clinicSystemId)
{
em.createNamedQuery("Clinic.deactivateByNotFoundInIncomingClinic")
.setParameter(1, clinicSystemId)
.getSingleResult();
}
答案 2 :(得分:1)
<强>程序强>
DROP FUNCTION updatename(bigint);
CREATE OR REPLACE FUNCTION updatename(var_id bigint)
RETURNS void AS $$
DECLARE
BEGIN
update person set
name ='lucas'
where id=var_id;
RETURN;
END;$$
LANGUAGE 'plpgsql';
//调用程序
Long id=50;
Query query = emProvider.get().createNativeQuery("SELECT updatename(?1)") ;
query.setParameter(1,id);
query.executeUpdate();