[hibernate-issues] [Hibernate-JIRA] Created: (HHH-3505) OptimizerFactory$HiLoOptimizer doesn't move internal idvalue to new slot when hiValue is reached

Björn Schmidt (JIRA) noreply at atlassian.com
Tue Sep 30 09:15:04 EDT 2008


OptimizerFactory$HiLoOptimizer doesn't move internal idvalue to new slot when hiValue is reached
------------------------------------------------------------------------------------------------

                 Key: HHH-3505
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3505
             Project: Hibernate Core
          Issue Type: Bug
          Components: core
    Affects Versions: 3.2.4
         Environment: Hibernate 3.2.4
            Reporter: Björn Schmidt


When the currently generated id-value has reached the TableGenerator's hivalue, all that is updated is the hivalue which is read in via the nextValue() callback. But the current idvalue needs to be readjusted to a new slot according to the new hiValue, because otherwise it may run into slots already assigned to and used by other applications. In our case, we got massive amounts of unique constraint-violations on many primarykey columns. 

Original Source:

		public synchronized Serializable generate(AccessCallback callback) {
			if ( lastSourceValue < 0 ) {
				lastSourceValue = callback.getNextValue();
				while ( lastSourceValue <= 0 ) {
					lastSourceValue = callback.getNextValue();
				}
				hiValue = ( lastSourceValue * incrementSize ) + 1;
				value = hiValue - incrementSize;
			}
			else if ( value >= hiValue ) {
				lastSourceValue = callback.getNextValue();
				hiValue = ( lastSourceValue * incrementSize ) + 1;
			}
			return make( value++ );
		}


This should look like:

		public synchronized Serializable generate(AccessCallback callback) {
			if ( lastSourceValue < 0 ) {
				lastSourceValue = callback.getNextValue();
				while ( lastSourceValue <= 0 ) {
					lastSourceValue = callback.getNextValue();
				}
				hiValue = ( lastSourceValue * incrementSize ) + 1;
				value = hiValue - incrementSize;
			}
			else if ( value >= hiValue ) {
				lastSourceValue = callback.getNextValue();
				hiValue = ( lastSourceValue * incrementSize ) + 1;
				// Adjust value to new Idslot.
 ------>                     value = hiValue - incrementSize;
			}
			return make( value++ );
		}


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       




More information about the hibernate-issues mailing list