hi expert, thanks for your reply, I know, whit that insert I am overwriting the default method for insert records.
But, I have another question, If I have a stored procedure (postgresql) that looks for a record description, If it isn't in the BBDD, then the function insert it and returns an integer with the id, something like:
Code:
CREATE OR REPLACE FUNCTION insert_host5(description character varying)
RETURNS integer AS
$BODY$
BEGIN
IF NOT EXISTS
(SELECT h.pk_codehost from public.x_hosts h WHERE h.d_host=description) THEN
INSERT INTO public.x_hosts
(
d_host
)
VALUES
(
description
);
END IF;
RETURN CURRVAL('x_hosts_pk_codehost_seq');
END
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION insert_host5(character varying)
OWNER TO postgres;
in my hbm.xml I have the next:
Code:
<sql-query name="callHostStoreProcedure">
<return-scalar column="pk_codehost" type="integer"/>
{? = call insert_host5(:description)}
<!--{? = Select * from insert_host5(:description) as t1}-->
</sql-query>
But when I execute it from java:
Code:
[b]Query query = session.getNamedQuery("callHostStoreProcedure2");
query.setString("description", sHost);
query.setResultTransformer(Transformers.aliasToBean(blom.log.model.xhost_sp.class));
List something = query.list();[/b]
I gives me an error:
org.hibernate.QueryException: Expected positional parameter count: 1, actual parameters: [] [{? = Select * from insert_host5(:description)}]
Any help please, for execute that function in hibernate
Thanks in advance