CHAPTER 8 Legacy databases and custom SQL needs

CHAPTER 8 Legacy databases and custom SQL needs to be updated) and expects your procedure to throw an exception if something goes wrong. In Oracle, such a procedure is as follows: create or replace procedure UPDATE_USER (IN_FIRSTNAME in varchar, IN_LASTNAME in varchar, IN_PASSWORD in varchar, … ) as rowcount INTEGER; begin update USERS set FIRSTNAME = IN_FIRSTNAME, LASTNAME = IN_LASTNAME, “PASSWORD” = IN_PASSWORD, where OBJ_VERSION = …; rowcount := SQL%ROWCOUNT; if rowcount != 1 then RAISE_APPLICATION_ERROR( -20001, ‘Version check failed’); end if; end; drop procedure UPDATE_USER The SQL error is caught by Hibernate and converted into an optimistic locking exception you can then handle in application code. Other options for the check attribute are as follows: If you enable check=”count”, Hibernate checks the number of modified rows using the plain JDBC API. This is the default and used when you write dynamic SQL without stored procedures. If you enable check=”param”, Hibernate reserves an OUT parameter to get the return value of the stored procedure call. You need to add an additional question mark to your call and, in your stored procedure, return the row count of your DML operation on this (first) OUT parameter. Hibernate then validates the number of modified rows for you.
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.