hibernate_annotation Field Mapping Location

Source: Internet
Author: User

@Id     Private int ID;     Private String name;     Private String wifename;     Private Date birthDate;     // title is an enum (enum) type    Private title  title; ***********************************       @Id    publicint getId () {        return  ID;    }

In Hibernate, the mapping @id can be placed on the member variable, completely.

In actual work, someone placed on the member variable, looking more focused and clearer. This, however, has destroyed Java's object-oriented encapsulation. Because when we write JavaBean, the attribute field is private.

If you write an annotation on your own, it is equivalent to hibernate directly accessing your private member variables, and the Java reflection mechanism can do that. But from a design point of view it is never recommended to do this, because in itself we set him up as private and we do not want others to reach us directly into our pockets to take our private things. For example, originally you put your home passbook into your pocket, add a lock, the results hibernate apart directly into your pocket to take out the passbook, inappropriate, so it should be suggested to write the note on the Get method. You should not go directly to the private variables, let alone hibernate to modify your private variables directly. It's even more unpleasant. Direct apart, put your passbook originally has 10000, directly to you change to 1 pieces.

And to keep the property name and set, get method consistent.

hibernate_annotation Field Mapping Location

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.