本帖最后由 weitongyixun 于 2010-02-22 09:39:16 编辑

解决方案 »

  1.   

    5.1.4.1. Generator
    The optional <generator> child element names a Java class used to generate unique identifiers for instances of the persistent class. If any parameters are required to configure or initialize the generator instance, they are passed using the <param> element. <id name="id" type="long" column="cat_id">
            <generator class="org.hibernate.id.TableHiLoGenerator">
                    <param name="table">uid_table</param>
                    <param name="column">next_hi_value_column</param>
            </generator>
    </id>
    hibernate 文档
    如果你想知道的话看源码吧!!!!
    native
    picks identity, sequence or hilo depending upon the capabilities of the underlying database.
    native
    picks identity, sequence or hilo depending upon the capabilities of the underlying database.
      

  2.   

    配置一下identity的属性 ,根据不同数据库配置不同的属性
      

  3.   

    在插入之前先取出bugno进行递增不行吗
      

  4.   

    org.springframework.jdbc.core.JdbcTemplateKeyHolder keyHolder = new GeneratedKeyHolder();
      

  5.   

    <id column="account_id" name="accountId" type="java.lang.Long">
    <generator class="increment" />
    </id>
      

  6.   

    建议楼主直接在数据库建一个sequence函数
    脚本
    -- Create sequence 
    create sequence HIBERNATE_SEQUENCE
    minvalue 1
    maxvalue 999999999999999999999999999
    start with 100233526
    increment by 1
    cache 20;
    然后直接用这个函数就可以了
    select hibernate_sequence.nextval from dual 
      

  7.   

    楼上各位 。。我的意思是想 在插入数据库之前 生成这个递增数 比如新增一条记录吧。。在新增的页面上就显示给用户看这个递增数(bugno) 然后在插入数据库。。
      

  8.   

    那你怎么控制锁?
    比如两个用户都点了登录,你给了id。id比较小的那个人取消登录,那不就空出一个了id了么?
      

  9.   

    hibernate id generator会自动帮你做这件事
      

  10.   

    能还是能做,但是会比较麻烦。
    建一个新的表,用来存储当前最大的sequence,每当用户要显示的时候就查这个表同时把最大值加一保存。这样的话就可以保证唯一性,和同步性。但是问题就是如果用户看了以后又不申请了的话你的这个值就没用了。
      

  11.   

    正解。。
    用hibernate,当然让hibernate来干这活了。。
      

  12.   


    因为我的表已经有主键了,单生成方式是uuid。hex
    表结构
    bugtablle
    id{pk},bugno
    这个bugno便是我要存储递增的数据的。
    像9楼说的--------------------------------------------------------------
    那你怎么控制锁? 
    比如两个用户都点了登录,你给了id。id比较小的那个人取消登录,那不就空出一个了id了么?
    ----------------------------------------------------------------------
    这个问题我暂时没有解决,现在只是用select max(bugno)每次读取到新增页面之前去加1.但是问题就是如果我删除了,bugno就不连续,还有得考虑多用户操作。
    如果要是创建sequence 的话。mysql的怎么创建。创建sequence后能否保证在删除 时候 bugno自动可以更新保持连续??
      

  13.   

    不能如果你只是想显示给用户看,为什么偏要在db里面加这个呢你在jsp页面 ,读取的时候 给每个记录加个编号不就行了么?