hibernate配置oracle生成序列结果为负数

来源:互联网 发布:mac水漾轻盈粉底液 编辑:程序博客网 时间:2024/06/06 12:44

工作中使用到了oracle12的版本,使用hibernate5保存时发现生成的结果除了1正常其余的都从-49开始往上加,

数据库自身查询是没有问题的。

跟踪hibernate5的源码发现@SequenceGenerator还需要配置一个allocationSize=1才能正常

@SequenceGenerator(name="UMS_USER_SEQ", sequenceName="UMS_USER_SEQ",allocationSize = 1)

相关源码在org.hibernate.id.enhanced.PooledOptimizer#generate

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 initialValueif ( ( 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 0
原创粉丝点击