When to use @Embedded and @Embeddable?

后端 未结 4 1017
别跟我提以往
别跟我提以往 2021-01-18 01:10

Is it possible to annotate a class as @Embeddable or a property as @Embedded?

Sample code:

@Embeddable
class A{
...
}

cla         


        
4条回答
  •  青春惊慌失措
    2021-01-18 01:37

    You would use @Embeddable and @Embedded together. You mark your class as @Embeddable, which indicates that this class will not exist in the DB as a separate table. Now when you use @Embedded on the field itself.

    The word embeddable and embedded gives you a big clue actually.

    Embeddable = This class can be embedded in a class Embedded = This class will now be embedded in your class as a field.

提交回复
热议问题