postgresql - Error when using custom function on NHibernate mapping-by-code's SqlInsert -


i have nhibernate mapping-by-code works if using standard insert on standard sqlinsert

class producttranslationmapping : classmapping<producttranslation> {     public producttranslationmapping ()     {         .         .         sqlinsert ("insert product_translation(product_id, language_code, product_name, product_description) values(?,?,?,?)");          .         .            } } 

however, want use postgresql stored procedure, both insert , update can use same routine

class producttranslationmapping : classmapping<producttranslation> {     public producttranslationmapping ()     {          .                .         sqlinsert ("select merge_product_translation(?,?,?,?)");         sqlupdate ("select merge_product_translation(?,?,?,?)");         .         .            } } 

however when use postgresql function, has error:

unhandled exception: nhibernate.stalestateexception: unexpected row count: -1; expected: 1   @ nhibernate.adonet.expectations+basicexpectation.verifyoutcomenonbatched (int32 rowcount, idbcommand statement) [0x00000] in <filename unknown>:0    @ nhibernate.adonet.nonbatchingbatcher.addtobatch (iexpectation expectation) [0x00000] in <filename unknown>:0    @ nhibernate.persister.entity.abstractentitypersister.insert (system.object id, system.object[] fields, system.boolean[] notnull, int32 j, nhibernate.sqlcommand.sqlcommandinfo sql, system.object obj, isessionimplementor session) [0x00000] in <filename unknown>:0  [error] fatal unhandled exception: nhibernate.stalestateexception: unexpected row count: -1; expected: 1   @ nhibernate.adonet.expectations+basicexpectation.verifyoutcomenonbatched (int32 rowcount, idbcommand statement) [0x00000] in <filename unknown>:0    @ nhibernate.adonet.nonbatchingbatcher.addtobatch (iexpectation expectation) [0x00000] in <filename unknown>:0    @ nhibernate.persister.entity.abstractentitypersister.insert (system.object id, system.object[] fields, system.boolean[] notnull, int32 j, nhibernate.sqlcommand.sqlcommandinfo sql, system.object obj, isessionimplementor session) [0x00000] in <filename unknown>:0  

if help, here's postgresql stored procedure:

create or replace function merge_product_translation(p_product_id int, p_language_code text, p_product_name text, p_product_description text) returns int $$ begin     if not exists(select * product_translation product_id = p_product_id , language_code = p_language_code)                insert product_translation(product_id, language_code, product_name, product_description)         values(p_product_id, p_language_code, p_product_name, p_product_description);     else                 update product_translation set             product_name = p_product_name,             product_description = p_product_description         product_id = p_product_id , language_code = p_language_code;         end if;      return 1;  end; $$ language 'plpgsql'; 

i tried following, still out of luck, of them has error:

sqlinsert ("perform merge_product_translation(?,?,?,?)"); sqlinsert ("call merge_product_translation(?,?,?,?)");   sqlinsert ("{call merge_product_translation(?,?,?,?)}");         

what should use can avoid error unexpected row count of -1? it's hard google it, google eliminates -1

nhibernate needs check results of internally generated sql commands. same required/applied on custom implementation (stored procedures), because treated same.

but there nice solution. read more here 17.3. custom sql create, update , delete.

the extract:

the stored procedures default required affect same number of rows nhibernate-generated sql would. nhibernate uses idbcommand.executenonquery retrieve number of rows affected. check can disabled using check="none" attribute in sql-insert element.

the solution: ... adjust mapping this:

<sql-insert check="none" >..</sql-insert> <sql-update check="none" >..</sql-update> 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -