Java - JPA @Basic and @Embedded annotations

前端 未结 3 2075
北海茫月
北海茫月 2020-12-07 17:38

I am learning JPA from this tutorial.

I have some confusions in understanding the following annotations:

  • @Basic
  • @Embedded
3条回答
  •  星月不相逢
    2020-12-07 18:17

    In ORM mapping, the granularity of your object model can be finer than that of your database.

    For example, you can have a Person record in your database which can be further decomposed to contain a reference to an Address object in your model. That's where the @Embedded and @Embeddable annotations come in. They simply state a relationship where one Entity can be stored as part of another.

    As for the @Basic annotation, it's the simplest form of mapping which is applied by default to primitive types such as int and float and their wrappers as well as enums. More information can be had here: http://docs.jboss.org/hibernate/stable/annotations/reference/en/html/entity.html#entity-mapping-property

提交回复
热议问题