I'm having similar problems.
Is there a working example of using stored procedures (or functions - PostgreSQL) for sql-insert and co?
Is check="none" the only workable solution?
I did basically this:
- in hbm:
Code:
<sql-insert callable="true">{call mydb.createMyEntity (?, ?, ?, ?, ?, ?, ?, ?)}</sql-insert>
Parameters are the same as in hibernates own SQL.
The function (DB is PostgreSQL 8.4) is:
Code:
CREATE OR REPLACE FUNCTION mydb.createMyEntity(
a_name character varying(50),
a_address character varying(200),
a_city character varying(100),
a_post_code character varying(10),
a_country_code character varying(3),
a_foo character varying(200),
a_bar_fk_id integer,
a_my_id integer
) RETURNS void AS $$
BEGIN
INSERT INTO mydb.my_table VALUES ($8, $7, $1 , $2 , $3, $4 , $5, $6 );
END;
$$ LANGUAGE plpgsql;
When I try to persist an object, I get this exception/log:
Code:
Hibernate: {call mydb.createMyEntity (?, ?, ?, ?, ?, ?, ?, ?)}
18:35:05.343 [main] ERROR org.hibernate.jdbc.AbstractBatcher - Exception executing batch:
org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
Should there be more in the stored function?
The stored function is called. I checked by putting RAISE EXCEPTION statements in it.
Regards,
David