<One-to-one> and <others-to-one> Single-ended associations can be set to false/proxy/noproxy (false/proxy/no proxy)
Instance 1: default for all lazy attributes (support for lazy loading)
Session = HibernateUtils.GetSession(); Tx = session. beginTransaction (); // Do not issue SQL statements. lazy (lazy loading) is supported) User user = (User) session. load (User.Class, 3 ); // Issue an SQL statement to load only common attributes. Data in the set is not loaded. System.Out. Println ("user. name =" + user. getName ()); // No SQL statement is issued and only the proxy class is returned. Group group = user. getGroup (); // Issue an SQL statement because the object is actually used System.Out. Println ("group. name =" + group. getName ()); Tx. commit (); |
Example 2: Set<Role-to-one>InLazySetFalse, Other default
Session = HibernateUtils.GetSession(); Tx = session. beginTransaction (); // The SQL statement is not sent User user = (User) session. load (User.Class, 3 ); // An SQL statement is sent and two SQL statements are sent, namely User and group. // Because lazy = false in <role-to-one>, the Group System.Out. Println ("user. name =" + user. getName ()); // It will not be sent, and data has been loaded on it Group group = user. getGroup (); // It will not be sent, and data has been loaded on it System.Out. Println ("group. name =" + group. getName ()); Tx. commit (); |
Example 3: Set<Class>InLazySetFalse, Other default
Session = HibernateUtils.GetSession(); Tx = session. beginTransaction (); // The SQL statement is sent because lazy = false in <class> User user = (User) session. load (User.Class, 3 ); // No SQL statement will be issued and it has been loaded on it System.Out. Println ("user. name =" + user. getName ()); // Will not be issued, because the lazy on the <class> label only has an impact on common attributes. // <Class>TagLazyDoes not affectLazyFeatures Group group = user. getGroup (); // Will be sent because the object is used System.Out. Println ("group. name =" + group. getName ()); Tx. commit (); |
020 <one-to-one> and <pull-to-one> lazy (lazy loading) attributes on single-ended associations