(day 2) hibernate 지식 훈련 (one - to - many)

1. one set     
<set name="acts" cascade="all" inverse="true"><!--  one (user)many (Account) -->
<key column="fid"></key>
<one-to-many class="Account"/><!--          Account  -->
</set>
 :inverse="true"                                                  ,                     。            
2. many 
<many-to-one name="user" column="fid" cascade="save"><!--        -->
</many-to-one>
 .  
1.        -->PO         (OOAD       -->PO     )
Transient     : po  Session  ,         
Persistent     : po  Session  ,        
Detached   /   :po Session  ,        
 : Session  , Session               
     :                    ,            ,           ,      Session      ,     Session.save()
    :          (new)   ,         ,     Session.delete(),
    :                    ,             ,    SessionSession    ,       ,               .
    -->   ?  -->     -- -->  
 (   )   (   ) -- -->Session  ? -->   
2.     :                                                                                                                                      _|_-->close():  Session/clear()       /evict()        
save() / saveOrUpdate()            close()/clear()/evict()
Transient--------------------->Persistent----------------------->Detached
 (   )<---------------------(   )<----------------------- (   )
delete()                    update()/saveOrUpdate()/lock() 
 .     cascade
cascade                                      .
1. none:            ,none
2. save-update:            (     )             ,          (   ),one2many           ;
3. delete:                        (   )。
4. all:                      (   )。
5. all-delete-orphan: nulldelete            id  null,           ,       delete-orphan        ,             。(    )
cascade="save-update,delete-orphan"
 .     (Batch update)
1. session.flush() session.clear()    
2. batch-size:       set   ,      ,                           ,             ,     ,                   ,   (lazy="true"  lazy="false")。                               
 :  lazy="true"     ,       ,               ,                                ,                     。       LazyInitializationException  ,                 ,                      ,  SessionSession,                   。
 . Hibernate     (ACID,atomicity consistency isolation durability)            ,               。
Transaction tran=session.beginTranaction();//....    
tran.commit();
tran.rollback();
          ,         。
hibernate       
hibernate        JDBC
     hibernate.cfg.xml  
<property name="hibernate.connection.isolation">4</property>
1,       (Read uncommitted isolation
2,       (Read committed isolation
4,      (Repeatable read isolation
8,      (Serializable isolation
hibernate  (   ,   )
1.    :            ,             ,     ,
LockMode.UPGRADE,get()
LockMode.NONE     
LockMode.READ    (JDBC  for update)
LockMode.WRITE 
  :tran = s.beginTransaction();
user = (User)s.get(User.class , userid , LockMode.UPGRADE); 
user.setName("new name");
tran.commit();
     Session.lock() Query.setLockMode() Criteria.setLockMode()      
2.    :   
       :     versionNo
if(read_versionNo=versionNo) write versionNo++ else do it again

< version name = "version" / > 는 < id > 이후 persist 를 따라 가 야 합 니 다.

좋은 웹페이지 즐겨찾기