Lazy initialization results for hibernate

Source: Internet
Author: User

 PackageCom.ehcache;Importjava.io.Serializable; Public classUserImplementsserializable{Private intID; PrivateString name;  PublicUser () {} Public intgetId () {returnID; }     Public voidSetId (intID) { This. ID =ID; }     PublicString GetName () {returnname; }     Public voidsetName (String name) { This. Name =name; } @Override PublicString toString () {return"User [id=" + ID + ", name=" + name + "]"; }    }
<?XML version= "1.0"?><!DOCTYPE hibernate-mapping Public "-//hibernate/hibernate mapping DTD 3.0//en" "http://www.hibernate.org/ Dtd/hibernate-mapping-3.0.dtd "><hibernate-mapping Package= "Com.ehcache">    <!--Name property: Which Class Table property: Which table, if not, the default table name is the simple name of the class -    <classname= "User"Table= "Tt_user" >        <Cacheusage= "Read-write" />        <IDname= "id">            <Generatorclass= "Native" />        </ID>        < Propertyname= "Name"Not-null= "true" />    </class></hibernate-mapping>
        @Test        publicvoid  test2 () {            = sessionfactory.opensession ();            Session.begintransaction ();             = Session.load (User.  Class, 1);
//This Side note the session closes after the print U1 will error no session //Hibernate.initialize (U1); Session.gettransaction (). commit (); Session.close (); System.out.println (U1); // return C1; }

Lazy initialization results for hibernate

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.