<bdo id='YrP7W'></bdo><ul id='YrP7W'></ul>

      <small id='YrP7W'></small><noframes id='YrP7W'>

      <legend id='YrP7W'><style id='YrP7W'><dir id='YrP7W'><q id='YrP7W'></q></dir></style></legend>
    1. <tfoot id='YrP7W'></tfoot>
    2. <i id='YrP7W'><tr id='YrP7W'><dt id='YrP7W'><q id='YrP7W'><span id='YrP7W'><b id='YrP7W'><form id='YrP7W'><ins id='YrP7W'></ins><ul id='YrP7W'></ul><sub id='YrP7W'></sub></form><legend id='YrP7W'></legend><bdo id='YrP7W'><pre id='YrP7W'><center id='YrP7W'></center></pre></bdo></b><th id='YrP7W'></th></span></q></dt></tr></i><div id='YrP7W'><tfoot id='YrP7W'></tfoot><dl id='YrP7W'><fieldset id='YrP7W'></fieldset></dl></div>

      休眠oracle序列产生大间隙

      时间:2023-09-20

      <small id='9yOJA'></small><noframes id='9yOJA'>

            <tbody id='9yOJA'></tbody>
          <legend id='9yOJA'><style id='9yOJA'><dir id='9yOJA'><q id='9yOJA'></q></dir></style></legend>

          <tfoot id='9yOJA'></tfoot>

            • <bdo id='9yOJA'></bdo><ul id='9yOJA'></ul>
              <i id='9yOJA'><tr id='9yOJA'><dt id='9yOJA'><q id='9yOJA'><span id='9yOJA'><b id='9yOJA'><form id='9yOJA'><ins id='9yOJA'></ins><ul id='9yOJA'></ul><sub id='9yOJA'></sub></form><legend id='9yOJA'></legend><bdo id='9yOJA'><pre id='9yOJA'><center id='9yOJA'></center></pre></bdo></b><th id='9yOJA'></th></span></q></dt></tr></i><div id='9yOJA'><tfoot id='9yOJA'></tfoot><dl id='9yOJA'><fieldset id='9yOJA'></fieldset></dl></div>
                本文介绍了休眠oracle序列产生大间隙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我使用的是 hibernate 3,oracle 10g.我有一张桌子:主题.定义在这里

                I am using hibernate 3 , oracle 10g. I have a table: subject. The definition is here

                CREATE TABLE SUBJECT
                    ( 
                     SUBJECT_ID NUMBER (10), 
                     FNAME VARCHAR2(30)  not null, 
                     LNAME VARCHAR2(30)  not null, 
                     EMAILADR VARCHAR2 (40),
                     BIRTHDT  DATE       not null,
                     constraint pk_sub primary key(subject_id) USING INDEX TABLESPACE data_index
                    ) 
                ;
                

                插入新主题时,sub_seq用于创建主题id,定义在这里

                when insert a new subject, sub_seq is used to create an subject id, the definition is here

                create sequence sub_seq
                       MINVALUE 1 
                       MAXVALUE 999999999999999999999999999 
                       START WITH 1
                       INCREMENT BY 1 
                       CACHE 100 
                       NOCYCLE ;
                

                Subject 类是这样的:

                the Subject class is like this:

                @Entity
                @Table(name="ktbs.syn_subject")
                public class Subject {
                
                    @Id 
                    @Column(name="subject_id")
                    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SUB_SEQ")
                    @SequenceGenerator(name="SUB_SEQ", sequenceName = "SUB_SEQ")
                    private long subjectId;
                    private String fname;
                    private String lname;
                    private String emailadr;
                    private Date birthdt;
                }
                

                在主题表中,数据库中有 4555 个主题由来自 excel 的 plsql 脚本加载,并且 sub_sequence 工作正常.主题 ID 范围为 1--4555.

                in the subject table , there have been 4555 subjects in the database loaded by plsql scripts from excel and the sub_sequence worked fine. subject ids range from 1--4555.

                但是,当我使用 hibernate 从我的应用程序中添加一个主题时,序号跳到了255050,运行几天后hibernate生成的subject id是这样的

                however, when i added a subject from my application using hibernate, the sequence number jumped to 255050. After several days running, the subject ids generated by hibernate look like this

                270079
                270078
                270077
                270076
                270075
                270074
                270073
                270072
                270071
                270070
                270069
                270068
                270067
                270066
                270065
                270064
                270063
                270062
                270061
                270060
                270059
                270058
                270057
                270056
                270055
                270054
                270053
                270052
                270051
                270050
                265057
                265056
                265055
                265054
                265053
                265052
                265051
                265050
                260059
                260058
                260057
                260056
                260055
                260054
                260053
                260052
                260051
                260050
                255067
                255066
                255065
                255064
                255063
                255062
                255061
                255060
                255059
                255058
                255057
                255056
                255055
                255054
                255053
                255052
                255051
                255050
                4555
                4554
                4553
                .
                .
                .
                .
                1
                

                有几个大的差距:4555到255051、255067到260051、265057到270051

                There are several large gaps: 4555 to 255051, 255067 to 260051, 265057 to 270051

                这是一种浪费,而不是一种理想的行为.

                this is a waste and not a desired behavior.

                有谁知道为什么会发生这种情况并且很容易修复它

                does anyone know why this happens and hot to fix it

                谢谢

                推荐答案

                我认为问题出在序列生成器并不是真正的序列生成器,而是序列hilo生成器,默认分配大小为50. 如文档所示:http:///docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/#entity-mapping-identifier

                I think that the problem comes from the fact that the sequence generator is not really a sequence generator, but a sequence hilo generator, with a default allocation size of 50. as indicated by the documentation : http://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/#entity-mapping-identifier

                这意味着如果序列值为 5000,则下一个生成的值将是 5000 * 50 = 250000.将序列的缓存值添加到等式中,它可能解释了您巨大的初始差距.

                This means that if the sequence value is 5000, the next generated value will be 5000 * 50 = 250000. Add the cache value of the sequence to the equation, and it might explain your huge initial gap.

                检查序列的值.它应该小于最后生成的标识符.注意不要将序列重新初始化为最后生成的值 + 1,因为生成的值会呈指数增长(我们遇到过这个问题,并且由于溢出而导致负整数 id)

                Check the value of the sequence. It should be less than the last generated identifier. Be careful not to reinitialize the sequence to this last generated value + 1, because the generated valus would grow exponentially (we've had this problem, and had negative integer ids due to overflow)

                这篇关于休眠oracle序列产生大间隙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:ORA-01882: 未找到时区区域 下一篇:Oracle JDBC ojdbc6 Jar 作为 Maven 依赖项

                相关文章

                • <bdo id='7NGvq'></bdo><ul id='7NGvq'></ul>
              • <tfoot id='7NGvq'></tfoot>
                <i id='7NGvq'><tr id='7NGvq'><dt id='7NGvq'><q id='7NGvq'><span id='7NGvq'><b id='7NGvq'><form id='7NGvq'><ins id='7NGvq'></ins><ul id='7NGvq'></ul><sub id='7NGvq'></sub></form><legend id='7NGvq'></legend><bdo id='7NGvq'><pre id='7NGvq'><center id='7NGvq'></center></pre></bdo></b><th id='7NGvq'></th></span></q></dt></tr></i><div id='7NGvq'><tfoot id='7NGvq'></tfoot><dl id='7NGvq'><fieldset id='7NGvq'></fieldset></dl></div>

                <small id='7NGvq'></small><noframes id='7NGvq'>

                  <legend id='7NGvq'><style id='7NGvq'><dir id='7NGvq'><q id='7NGvq'></q></dir></style></legend>