原文链接:http://blog.csdn.net/z634075513/article/details/51554194
工作中使用到了Oracle12的版本,使用hibernate5保存时发现生成的结果除了1正常其余的都从-49开始往上加,
数据库自身查询是没有问题的。
跟踪hibernate5的源码发现@SequenceGenerator还需要配置一个allocationSize=1才能正常
如
@SequenceGenerator(name="UMS_USER_SEQ", sequenceName="UMS_USER_SEQ",allocationSize = 1)
相关源码在org.hibernate.id.enhanced.PooledOptimizer#generat
generationState.value = callback.getNextValue(); // 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... if ( generationState.value.lt( 1 ) ) { log.pooledOptimizerReportedInitialValue( generationState.value ); } // the call to obtain next-value just gave us the initialValue if ( ( initialValue == -1 && generationState.value.lt( incrementSize ) ) || generationState.value.eq( initialValue ) ) { generationState.hiValue = callback.getNextValue(); } else { generationState.hiValue = generationState.value; generationState.value = generationState.hiValue.copy().subtract( incrementSize - 1 ); }问题:
1.有如下sequenceGenerator,用的哪个?
sequenceGenerator: (sequenceHiLoGenerator, sequenceIdentityGenerator)
sequenceStyleGenerator
2.有如下Optimizer, 用的哪个?
PooledOptimizer/PooledLoOptimizer/HiLoOptimizer/LegacyHiLoAlgorithmOptimizer()/NoopOptimizer;
新闻热点
疑难解答