@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