Hibernate the generation of annotations-based sessionfactory classes and the automatic generation of table Schemaexport classes

Source: Internet
Author: User

Like before based on the mapping file. Hbm.xml's Sessionfactory class is like this.

<span style= "Font-size:18px;color: #33CC00;" >private static sessionfactory sessionfactory; static{sessionfactory = new Configuration (). Configure (). Buildsessionfactory ();} </span>

The class Schemaexport that automatically generates the database schema is like this.

<span style= "Font-size:18px;color: #FF0000;" >schemaexport schemaexport = new Schemaexport (new Configuration (). Configure ()); Schemaexport.create (true,true); </span>

However, the notation-based Sessionfactory class is written like this

<span style= "Background-color:rgb (51, 255, 51); ><span style= "FONT-SIZE:18PX;" >static{sessionfactory = new Annotationconfiguration (). Configure (). Addpackage ("Com.test.hibernate"). Addannotatedclass (Car.class). Buildsessionfactory ();} </span></span>

And then the database automatically generates schema for the schemaexport.

<span style= "Background-color:rgb (51, 255, 51); ><span style= "FONT-SIZE:18PX;" >schemaexport schemaexport =new Schemaexport (New Annotationconfiguration (). Configure (). Addpackage (" Com.test.hibernate "). Addannotatedclass (Car.class)); Schemaexport.create (True,false);</span></span>




Hibernate the generation of annotations-based sessionfactory classes and the automatic generation of table Schemaexport classes

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.