Object object,
int timeout, SessionImplementor session) throws StaleObjectStateException, JDBCException {
if ( !lockable.isVersioned() ) {
throw new HibernateException( "write locks via update not supported for non-versioned entities [" + lockable.getEntityName() + "]" );
}
SessionFactoryImplementor factory = session.getFactory();
try {
PreparedStatement st = session.getBatcher().prepareSelectStatement( sql );
try {
lockable.getVersionType().nullSafeSet( st, version, 1, session );
int offset = 2;
lockable.getIdentifierType().nullSafeSet( st, id, offset, session );
offset += lockable.getIdentifierType().getColumnSpan( factory );
if ( lockable.isVersioned() ) {
lockable.getVersionType().nullSafeSet( st, version, offset, session );
}
int affected = st.executeUpdate();
if ( affected < 0 ) { // todo: should this instead check for exactly one row modified?
factory.getStatisticsImplementor().optimisticFailure( lockable.getEntityName() );
throw new StaleObjectStateException( lockable.getEntityName(), id );
}
}
finally {