sha*_*ltc 17 java orm spring hibernate jpa
这一定是天真的,但我怀疑何时使用@Entity和@Embeddable.
说我有一个User和一个Notification班级.
@Entity
public class User{
//other properties
@onetomany
private List<Notification> notifications;
}
@Entity
public class Notification{
//properties
}
Run Code Online (Sandbox Code Playgroud)
据我所知,将有类表User和Notification,以及映射第三个表.如果我这样做怎么办?
@Entity
public class User {
//other properties
@ElementCollection
private List<Notification> notifications;
}
@Embeddable
public class Notification{
//properties
}
Run Code Online (Sandbox Code Playgroud)
我知道这不会创建一个表Notification.但我仍然可以存储我的通知对象.我浏览了文档,但有些疑惑:
笔记
对于读这个问题的人来说,这个问题也可能对你有帮助.
是的,当您使用时@Embedded,您将该@Embeddable实体嵌入到@Entity类中,这使得它可以在同一个@Entity类表中添加嵌入实体的列.
使用时@Embedded,对于表创建,需要一个查询,也用于插入和选择行.但是,如果你不使用它,则需要多个查询,因此,使用@Embedded产生更多性能,我们可以说.
删除相应的嵌入实体可能是,但可能存在完整性约束违规.
| 归档时间: |
|
| 查看次数: |
18612 次 |
| 最近记录: |