开发者

oracle stored procedure generates larger numbers through hibernate than it does alone

We have a stored procedure that generates numbers for entry ids (entry_id_seq). With the following setting, the code generates a relatively large number than it is called with SQL directly.

For instance, the following code generates a number "11195215652" for id. But if I run select entry_id_seq.NEXTVAL nv from dual, it returns开发者_JAVA技巧 "32350910" which is a lot smaller.

@javax.persistence.SequenceGenerator(name = "seq",
sequenceName = "entry_id_seq")
public class SomeClassimplements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq")
    @Column(name = "ID")
    private Long id;

I tried the suggestion below

@javax.persistence.SequenceGenerator(name = "seq",
sequenceName = "entry_id_seq", allocationSize = 1, initialValue= 1)

but it gives me the following error:

Caused by: org.hibernate.HibernateException: increment size cannot be less than 1
    at org.hibernate.id.enhanced.OptimizerFactory$LegacyHiLoAlgorithmOptimizer.<init>(OptimizerFactory.java:336)
    at org.hibernate.id.SequenceHiLoGenerator.configure(SequenceHiLoGenerator.java:64)
    at org.hibernate.id.factory.DefaultIdentifierGeneratorFactory.createIdentifierGenerator(DefaultIdentifierGeneratorFactory.java:110)


What version of hibernate are you using? If < 3.5.3 then check this https://hibernate.onjira.com/browse/HHH-5230

It appears that it affects legacy generators with allocationSize = 1 configured with annotations.

Resolution: 1. configure to use new generators, 2.Upgrade, 3.patch your version manually.


Per discussion on: https://forum.hibernate.org/viewtopic.php?t=973682

the solution is: In the SequenceGenerator annotation, add allocationSize = 1, initialValue= 1

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜