本文介绍了有人可以在休眠中解释我@MapsId 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

有人可以在休眠中向我解释 @MapsId 吗?我很难理解它.

Can someone please explain to me @MapsId in hibernate? I'm having a hard time understanding it.

如果能用一个例子来解释它,以及它最适用于哪种用例,那就太好了?

It would be great if one could explain it with an example and in what kind of use cases is it most applicable?

推荐答案

这里有一个很好的解释来自 对象数据库.

Here is a nice explanation from Object DB.

指定 ManyToOne 或 OneToOne 关系属性,为 EmbeddedId 主键、EmbeddedId 主键中的属性或父实体的简单主键提供映射.value 元素指定关系属性对应的组合键中的属性.如果实体的主键与关系引用的实体的主键的 Java 类型相同,则不指定 value 属性.

// parent entity has simple primary key

@Entity
public class Employee {
   @Id long empId;
   String name;
   ...
}

// dependent entity uses EmbeddedId for composite key

@Embeddable
public class DependentId {
   String name;
   long empid;   // corresponds to primary key type of Employee
}

@Entity
public class Dependent {
   @EmbeddedId DependentId id;
    ...
   @MapsId("empid")  //  maps the empid attribute of embedded id
   @ManyToOne Employee emp;
}

阅读 API 文档 在这里.

这篇关于有人可以在休眠中解释我@MapsId 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 03:05