首页 > 数据库 > Oracle > 正文

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

2024-08-29 13:54:25
字体:
来源:转载
供稿:网友

原文链接: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;


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表