the difference between anotating a field and its getter method JPA

前端 未结 2 819
予麋鹿
予麋鹿 2021-01-06 21:09

i\'m trying to figure wether there\'s a difference betweeen anotating (let\'s take @id as an example) a getter method and the concerned field directly , in case i annotate

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-06 21:31

    JPA allows for two types of access to the data of a persistent class. Field access which means that it maps the instance variables (fields) to columns in the database and Property access which means that is uses the getters to determine the property names that will be mapped to the db. What access type it will be used is decided by where you put the @Id annotation (on the id field or the getId() method).

提交回复
热议问题