Hibernate access policy for accessing persisted class properties

Source: Internet
Author: User

Access property usage for the <property> element:
Access has two optional values:
1,property: This is the default value, which indicates that hibernate accesses the properties of the class through the set and get methods. This is the preferred method of recommendation. You must set the get and set methods for this property to be accessed by hibernate. Otherwise it will be an error.
2,field: Indicates that hibernate accesses the properties of the class directly through the reflection mechanism of java. You can not set the get and set properties for this property.

This property works well when we piece together a user name. The following example:

Java code
  1. Public class Customer implements Serializable {
  2. /** 
  3. *
  4. */
  5. private Static final long serialversionuid = 1L;
  6. Private String FirstName;
  7. private String LastName;
  8. Public String GetName () {
  9. return firstname + "" + LastName;
  10. }
  11. public void SetName (String name) {
  12. StringTokenizer t = new StringTokenizer (name);
  13. FirstName = T.nexttoken ();
  14. LastName = T.nexttoken ();
  15. }
  16. }


There is no need to configure the FirstName and LastName properties in the persistence mapping file for this class, but to map the Name property, as we end up with the full name.

Java code
    1. <property name="name" column="name"/>


Although the name attribute is not defined in the customer class, hibernate does not directly access the Name property, but is accessed through SetName and GetName. Regardless of whether the name attribute exists in the customer class, as long as the name attribute is mapped in the mapping file, HQL can access it, whereas the FirstName and LastName properties do not have a mapping in the mapping file, so the two properties cannot be accessed in HQL.

Hibernate access policy for accessing persisted class properties

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.