[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3628?page=c...
]
Montagnon Cyril commented on HHH-3628:
--------------------------------------
1) Tara, Steve Eversole 'highly recommends' not to use the NON enhanced
TableGenerator.
I'm not sure he doesn't recommend using the enhanced TableGenerator.
"The second is the more risky replacement because of the big difference between the
two. But we've all along discouraged direct use of the current "table"
generator so I think we should be safe there. I am still uncertain when that replacement
will happen (probably 4.0?), but in the meantime, the new generators are available and
highly recommended for use. "
I agree with you : it's critical!
2) The pooled optimizer works in a multi-jvm'ed environment. The generate() method is
correct (the 'value' is reset in the else if part ) :
public synchronized Serializable generate(AccessCallback callback) {
if ( hiValue < 0 ) {
value = callback.getNextValue();
if ( value < 1 ) {
// unfortunately not really safe to normalize this
// to 1 as an initial value like we do the others
// because we would not be able to control this if
// we are using a sequence...
log.info( "pooled optimizer source reported [" + value + "] as the
initial value; use of 1 or greater highly recommended" );
}
hiValue = callback.getNextValue();
}
else if ( value >= hiValue ) {
hiValue = callback.getNextValue();
value = hiValue - incrementSize;
}
return make( value++ );
}
Hilo optimizer problem in case of multiple threads accessing the
sequence table
-------------------------------------------------------------------------------
Key: HHH-3628
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3628
Project: Hibernate Core
Issue Type: Bug
Affects Versions: 3.2.6
Environment: Sybase
Reporter: Montagnon Cyril
If 2 (or more) threads access the table storing the ids, this optimizer won't work
and will try to insert entities with twice the same idea.
The problem is the way the HiLoOptimizer class generates the id :
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++ );
}
In the 'else if' part, the 'value' variable isn't reaffected, which
means the current thread will try to insert entities with an id that has already been used
by another thread. The value should be reset with hiValue - incrementSize.
--
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....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira