最近在学习hibernate,有几个问题,请教大家:
 1关于批处理操作
   通过Session来进行批量操作会受到以下约束
   ...
   (2)如果对象采用"identity"标识符生成器,则Hibernate无法在JDBC层进行批量插入操作。(为什么identity不行,identity不行的话,native也应该不可以。那么sequence可以吗?) 2关于脏数据处理
  Transaction tx=session.beginTransaction();
  User user=(User)session.load(User.class,”1”);//从数据库中加载符合条件的数据
  user.setName(“zx”);//改变了user对象的姓名属性,此时user对象成为了所谓的“脏数据”
  tx.commit();
  
  书上说hibernate在第二行的时候会在内存中保存user对象快照,以便后来commit前检查,是否发生改变。请问内存快照是怎么做的?
我查资料说hibernate使用的是拦截器setter(),改变标志位。也有说用数据版本比对.
谢谢。

解决方案 »

  1.   

    identity:自动增长,由底层数据库生成标识符;
    如果是批量插入操作,hibernate会把这一批做为一次提交。
    我也不知。
    我一般是用assigned:手动指派;通过sql的select max得到最大id,赋给对象,再用hibernate保存
      

  2.   

    1.一般都是用sequence 不过没试过插入大量的数据
    因为hibernate本身不太适合批量操作
    2.很少用load将对象加入内存中 一般修改的前查询出来 然后覆盖需要修改的属性
    也就没遇到过脏数据hibernate用的不多 楼下高手继续~~
      

  3.   

    identity是自动增长,mysql数据库可以支持,因为mysql主键可以自动增长,oralce就不行。如果是oracle,就用sequence吧用native是可以的,native是与数据库无关的,mysql的话就自动增长,oralce就会创建默认序列
      

  4.   

    主要看你用什么数据库了,identity 适用于sql,native适合mysql,只要有序列的就用sequence,如oracle,postgresql;
    第二个问题搞不清你说的什么意思,也许它只是load出一个新对象,执行saveorupdate的时候和原对象比较,不一致则执行save或者update吧
      

  5.   

    identity是自动增长,mysql数据库可以支持,因为mysql主键可以自动增长,oralce就不行。如果是oracle,就用sequence吧用native是可以的,native是与数据库无关的,mysql的话就自动增长,oralce就会创建默认序列
      

  6.   

    获取java应用程序内存快照 Microsoft Windows XP [版本 5.1.2600]
    (C) 版权所有 1985-2001 Microsoft Corp.C:\Documents and Settings\chen56>jmap
    Usage:
        jmap -histo <pid>
          (to connect to running process and print histogram of java object heap
        jmap -dump:<dump-options> <pid>
          (to connect to running process and dump java heap)    dump-options:
          format=b     binary default
          file=<file>  dump heap to <file>    Example:       jmap -dump:format=b,file=heap.bin <pid>C:\Documents and Settings\chen56>jps
    6888 FtpServer
    7500 BoostMain
    5876 BoostMain
    6780 Jps
    6264 BootMainC:\Documents and Settings\chen56>jps
    6888 FtpServer
    5876 BoostMain
    6264 BootMain
    3124 JpsC:\Documents and Settings\chen56>jmap -dump:format=b,file=e:/um2010121
    61643.bin 5876
    Dumping heap to E:\um201012161643.bin ...
    Heap dump file createdC:\Documents and Settings\chen56>