The precedence relationship between Hibernate entity classes and the default values of data table fields

Source: Internet
Author: User

In the daily application development process, we generally use object-relational mapping to solve the database operation through the object-oriented programming model, we use more in the production process is the Hibernate framework, he is very flexible, provide us with a variety of ways to achieve the operation and management of the data layer. By mapping the entity class to the data table, the entity class corresponds to the table, the property corresponding field can assign the object we want to produce to the database, but we also sometimes need to query the object, but no matter what operation, we must pass the data through the entity class.

Sometimes we database some fields are automatically assigned to the database, prohibit the user through the program modification, such as record generation time, then if your entity class under normal circumstances, you will certainly exist in order to query the corresponding fields, but you will find that when you add new records, The database does not automatically generate the corresponding record creation time for you, which is why? Because if you do not give the value of the corresponding field in the entity class, Hibernate will assume that you did not assign a value to him, the default value is NULL, so the system will not generate the creation time for you, the default value of the database field is that you do not give the value of the field when you automatically added, If you do not explicitly indicate the value of the field, so in order to solve this problem, we should use the annotation @transient the following two kinds of scenarios:

  1. An attribute that exists in an entity class does not have a corresponding field in the database table.
  2. Attributes that exist in an entity class do not need to be persisted into a database table.

Sometimes when the field is complex, in order to solve the problem of complex lines, we need to pass two entity classes to solve the problem.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The precedence relationship between Hibernate entity classes and the default values of data table fields

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.