Hibernate learning 8-hibernate ing File 5-property elements

Source: Internet
Author: User

The element defines a persistent, JavaBean-style attribute for the class.

L common attributes that can be used are as follows:

Name-attribute name of the corresponding class

Type-specifies the type of the attribute. Generally, you do not need to specify the attribute. hibernate automatically matches the attribute (see the description in this document)

Length-specify the length

Column-specifies the name of the database field corresponding to the attribute. If this parameter is not specified, it indicates the name of the attribute.

Element attributes:

1) Name: name of the attribute, starting with a lowercase letter.

2) Column (optional-attribute name by default): name of the corresponding database field. You can also use nested
Element.

3) type (optional): name of a hibernate type.

4) Update, insert (optional-true by default): indicates whether the ing field is included in the SQL statements used for update and/or insert. If both of them are set to false, it indicates that this is an "exogenous (derived)" attribute, and its value comes from some other attributes mapped to the same (or multiple) field, or through a trigger or anotherProgramGenerate.

5) formula (optional): An SQL expression that defines the value of the computed attribute. The calculation attribute does not have the corresponding database field.

6) Access (optional-default value: Property): the policy that hibernate uses to access attribute values.

7) lazy (optional-the default value is false): Specifies whether this attribute is delayed (fetched lazily) when the specified instance variable is accessed for the first time (requires enhanced runtime bytecode ).

8) Unique (optional): Use DDL to add unique constraints for this field. Similarly, it is allowed as the target referenced by property-Ref.

9) Not-null (optional): Use DDL to add nullability constraints for this field.

10) optimistic-lock (optional-the default value is true): Specifies whether this attribute requires Optimistic Locking when updating (optimistic lock ). In other words, it determines whether the value of version increases when dirty data occurs in this attribute.

11) generated (optional-never by default): indicates whether the attribute value is actually generated by the database.

Note:

The type names can be as follows:

N hibernate basic type name

For example: integer, String, character, date, timestamp, float, binary, serializable, object, blob

N Java type

Int, float, Char, java. Lang. String, java. util. Date, java. Lang. integer, java. SQL. clob

N name of a serializable Java class

N name of a custom type class

the access attribute allows you to control how hibernate accesses the attribute at runtime. By default, Hibernate uses the get/Set Method (pair) Of the attribute ). If you specify access = "field", Hibernate will ignore the get/Set Method pair and directly use reflection to access member variables. You can also specify your own policy, which requires you to implement the org. hibernate. Property. propertyaccessor interface by yourself, and then set the name of your custom policy class in access.

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.