Atitit. Improved development efficiency --- the revolution of the MDA software development mode (3) ---- automatic table Creation

Source: Internet
Author: User

Atitit. Improved development efficiency --- the revolution of the MDA software development mode (3) ---- automatic table Creation

 

1. Automatically create table 1 after modeling

1. Traditionally, you need to create a table first, in the Business Code... 1

2. model-driven table creation-more simplification is to automatically create table 1 after modeling

2. Principle of automatic table creation: 1

3. Automatic table creation tools: hibernate. hbm2ddl and hibernate4.1 2

4. hbm2ddl best practices 2

3. hibernate. hbm2ddl. Auto 2

5. Java statement execution 3

6. Use ant to execute hbm2ddl 3

7. QA 4

4. Table 'gialenweixin. gv_material 'doesn' t exist 4

5. hibernate attribute "value" must be declared for element type "property". 4

8. Refer to 4

 

 

1. Create a table automatically after modeling. 1. Traditionally, you need to create a table first ..

1. Abstract: many programs only have source code and do not have any matching database SQL statements. This is not easy to demonstrate or operate.

 

2. model-driven table creation-more simplification is to automatically create a table after modeling

 

Author: old wow's paw attilax iron, email: [email protected]

Reprinted please indicate Source: http://blog.csdn.net/attilax

 

2. Principle of automatic table creation:

SQL generation: Read annotation, generate SQL, and execute SQL

 

3. Automatic table creation tools: hibernate. hbm2ddl and hibernate4.1

With the hibernate library and database connection driver.

The database must be connected and no tables are available.

Hibernate4.1 can automatically create tables. Therefore, you only need to develop your own tables and configure them. No need to consider how to create a table

Hibernate configuration file generation SQL File

 

4. hbm2ddl Best Practices

Update only updates the table structure, but cannot generate... so you can use the create Attribute first, and then use update after running it once to avoid data loss.

 

3. hibernate. hbm2ddl. Auto

 

<Property name = "hibernate. hbm2ddl. Auto" value = "Update"/>

Update:
The most common attribute. When Hibernate is loaded for the first time, the table structure will be automatically created based on the model class (the premise is that the database is established first). When Hibernate is loaded, the table structure will be automatically updated based on the model class, even if the table structure is changed, the row in the table still does not delete the previous row. Note that after the application is deployed to the server, the table structure will not be created immediately. It will not be created until the application runs for the first time.
Validate:
Each time Hibernate is loaded, the system verifies the creation of the database table structure and only compares it with the table in the database. No new table is created, but a new value is inserted.

 

 

The hbm2ddl tool is a jar

 

Hbm2ddl

5. Java statement execution

Config = new configuration ()

. Configure (new file ("src/hibernate. cfg. xml "));

Schemaexport = new schemaexport (config );

Schemaexport. setoutputfile ("E: \ sql1.txt ");

Schemaexport. Create (true, false );

System. Out. println ("table created .");

 

 

6. Use ant to execute hbm2ddl

 

· <! -- Create DDL form *. HBM. xml -->

· <Target name = "hbm2ddl"

· Description = "generate dB schema from the O/R Mapping Files">

· <Taskdef name = "hbm2ddl"

· Classname = "org. hibernate. tool. Ant. hibernatgateltask"

· Classpathref = "Libraries"/>

· <Hbm2ddl destdir = "$ {ddlsqldir}">

· <Configuration configurationfile = "$ {basedir}/hibernate. cfg. xml"/>

· <Hbm2ddl export = "true" console = "false" create = "true" update = "false" Drop = "false" outputfilename = "DDL. SQL"/>

· </Hbm2ddl>

· </Target>

·

7. qa4. table 'gialenweixin. gv_material 'doesn' t exist

Update only updates the table structure, but cannot generate... so you can use the create Attribute first, and then use update after running it once to avoid data loss.

 

5. hibernate attribute "value" must be declared for element type "property ".

 

<Property name = "hibernate. hbm2ddl. Auto" value = "Update"/>

Change to... HB ver HB4

<Property name = "hibernate. hbm2ddl. Auto"> Update </property>

 

8. Reference

Hibernate4.0+ and 3.0 _xidianzxm_xinlang.htm

Hibernate uses @ dynamicinsert and @ dynamicupdate to generate a dynamic SQL statement-quantseven-blog. htm

Hibernateconfiguration file generation sqlfile _zjha4148_sina blog .htm

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.