Hibernate beginner 4--hbm2ddl

Source: Internet
Author: User

In Hibernate configuration file, there is the following code!!

1 <!--  -2  <name = "Hbm2ddl.auto" > Create/create-drop/update/validate</Property>

In the study, completely do not know the value of the attribute tag is the meaning of the symbol!! There are four types of tag values:

(1) Create

(2) Create-drop

(3) Update

(4) Validate

---------------------------------------------------------------------------------------

(1) When the property value is create

1  <!--  -2  <name = "Hbm2ddl.auto" > Create</Property>

Before running:

The results of the operation are as follows:

The analysis shows that when the parameter is create, hibernate will determine whether there are tables that need to be manipulated. If present, the table is deleted and recreated, otherwise it is created directly. (Student, teacher tables are present because student, teacher mappings have been added to the configuration file before the experiment, so student and teacher tables will be manipulated)

After running:

(2) When the attribute value is Create-drop, the test result is as follows (the employee table is deleted first)

Before running:

Operation Result:

Analysis shows that: Create-drop and create have the same characteristics, at run time will be detected in the database there is a need to operate the table, if there is the deletion of the reconstruction, does not exist directly new;

However, by displaying the tables in the database, the previously rebuilt or newly created table will be deleted as the program ends after the program runs.

After running:

(3) When the property value is update

Before running:

The results of the operation are as follows:

After running:

The analysis shows that hibernate automatically creates this table when there are no tables in the database that need to be manipulated.

When an attribute wage is added (that is, adding a field)

Operation Result:

After running:

The analysis indicates that hibernate does not delete the original table when there are tables in the database that need to be manipulated. The added field indicates that the previously inserted information was not deleted, so hibernate does not delete the table that needs to be manipulated in the database, but modifies it on the basis of the original table.

When you reduce one field and modify another field type

Operation Result:

After running:

The analysis shows that when the field is deleted, the newly inserted data does not have the deleted field and is represented as null in the table in order to not affect the previously inserted data, so it is shown as null on this field (via select * FROM employee where branch= ""; results can be derived , that is, the data you insert when you delete a field does not have the field you deleted.

The analysis shows that when inserting the data, the data table still has the deleted fields, so in the process of inserting the data later, the deleted fields need to be added.


The analysis shows that the data inserted when the field type is modified is typeface with the original data, and can not be found by the search method.

However, the problem comes again, the following test!! And this conclusion is different, seek expert explanation!!

The final conclusion: only according to the mapping file to the database and the table corresponding, if inconsistent, the structure of the Update table, so there are so many inconsistencies.

When the property value is validate

After running:

Analysis: The pit father, cannot explain!!! Ask to see the explanation of the aunt explained!! The visual is very similar to the update.

Other people's conclusion: the calibration map file and the database table is not able to correspond, can not correspond to the error, the actual use (not read)

Hibernate beginner 4--hbm2ddl

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.