Hibernate Persistence object status

Source: Internet
Author: User
1. from the perspective of persistence, Hibernate divides objects into four states: Persistence State, temporary state, free state (off-tube State), and deletion state. the Session method can convert an object from one state to another. 2. temporary status (Transient): 1 ). when the proxy primary key is used, the OID is generally null2

1. from the perspective of persistence, Hibernate divides objects into four states: Persistence State, temporary state, free state (off-tube State), and deletion state. the Session method can convert an object from one state to another. 2. temporary status (Transient): 1 ). when the proxy primary key is used, the OID is usually null 2

1. From the perspective of persistence ,Hibernate divides objects into four states. :Persistence status ,Temporary status ,Free Status (off-pipe status) ,Delete state. The Session method can convert an object from one state to another.
2. temporary status (Transient) :1). When the proxy primary key is used ,OID is usually null 2). It is not in the Session cache 3). There is no corresponding record in the database
3. Persistence status (Also called "hosting" )(Persist)
1). OID is not null 2). It is located in the Session cache 3). If there is a corresponding record in the database ,The persistence object corresponds to the related records in the database. 4) The Session is stored in FlushCache Time ,Will change according to the attributes of the Persistent Object ,To synchronously update the database. 5) in the cache of the same Session instance ,Each record in the database table only corresponds to a unique Persistent Object (the OID of the Session cache object cannot be repeated)
@ Test public void testOID (){News news2 = (News )Session. get (News. class ,1 );System. out. println (News2 );News news =New News ();News. setAuthor ("Oracle2" );News. setContent ("Oracle DB" );News. setDate (New Date ());News. setTitle ("DB" );News. setId (1 ); //Throw an exception: org. hibernate. NonUniqueObjectException session. update (News ); }
4. Free Status (It is also called "off-pipe" )(Detached): 1). OID is not null 2). It is no longer in Session cache 3). Generally, you need ,Free objects are transformed from persistent objects. ,Therefore, there may be records corresponding to the database.
5. Deletion Status (Removed )1). There is no record corresponding to its OID in the database. 2). It is no longer in the Session cache. 3). Generally ,The application should no longer use the deleted object.
6. Status transition diagram
7. Differences between get and load: get and load an object from a data table ,Differences between objects in persistent state after loading: get : <喎?http: www.2cto.com kf ware vc " target="_blank" class="keylink"> Examples + examples + INHTs9my6dGvyv2 + examples/examples + IDxzdHJvbmc + examples + KCk7PC9zdHJvbmc + examples/ release/release + 21 M/release + yPS21M/release + Cgo8YnI + release + sKO6IEJcUyDP7sS/1tC009Kzw + release /authorization + cgokos4gc2f2zu9yvxbkyxr1_xzdhjvbmc + KCk6PC9zdHJvbmc + ilgjtoa7811680mikcjxpbwcgc3jjjpq =" http://www.2cto.com/uploadfile/2014/1107/20141107092134167.png "Alt =" \ ">
11. delete (): Delete the record corresponding to an object. 1). If you only want to delete the specified object, set the ID. 2) If no corresponding record exists in the data table, an exception is thrown: java. lang. IllegalArgumentException
12. Hibernate calls the native jdbc api:
Session. doWork (New Work () {@ Override public void Execute (Connection connection )Throws SQLException { //Use the JDBC native API } });

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.