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:
- An attribute that exists in an entity class does not have a corresponding field in the database table.
- 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