The three states of hibernate learning and their life cycle

Source: Internet
Author: User

Three different states:

Life cycle:

The code indicates:

//三种状态    publicvoidtestThreeState(){        TUser user=newTUser();        user.setName("spark");  //此时user处于Transient                try{            Transaction tx=session.beginTransaction();            session.save(user); //user对象已经由hibernate纳入管理器,处于persistent状态            tx.commit();            session.close();   //user对象此时为Detached状态,因为与其关联的session已经关闭                        Transaction tx2=session2.beginTransaction();            session2.update(user);//user对象借助session2,由hibernate纳入管理容器,恢复persistent状态   update并没有发送sql语句            user.setName("spark_1");//处于persistent状态,其属性变更将自动由hibernate固话到数据库中   !!!!            tx2.commit();           //commit之前调用session.flush()在其中发送sql语句        } catch(HibernateException e) {            e.printStackTrace();        }    }

Three states and life cycles of hibernate learning (graph)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.