首先,我有两个Entities Folder和FolderObjectID及其对应的表。
在文件夹表上我有复合键FolderID和ParentFolderID
Table Folder
+----------------+
| Folder |
+----------------+
|#FolderID |
|#ParentFolderID |
+----------------+
在FolderObjectID表上,我将FolderObjectID作为主键。
Table FolderObjectID
+----------------+
| FolderObjectID |
+----------------+
|#FolderObjectID |
+----------------+
文件夹实体
@Entity
@Table(name = "Folder")
public class Folder implements java.io.Serializable {
private FolderId id;
//setter getter
}
嵌入式课程
@Embeddable
public class FolderId implements java.io.Serializable {
private Integer folderId;
private Integer parentFolderId;
//setter getter
}
FolderObjectID实体
@Entity
@Table(name = "FolderObjectID")
public class FolderObjectID implements java.io.Serializable {
private folderObjectId id;
//setter getter
}
现在我想拥有的是两个实体上的一对一关系,使用Folder表的FolderID列链接FolderObjectID表的FolderObjectID列。不幸的是,我收到错误,说我的文件夹实体上的列已经坏了。
有人可以就此事启发我。 感谢。
答案 0 :(得分:0)
我想使用@MapsId
功能。
与此类似,但我还没有尝试过:
文件夹实体
@Entity
@Table(name = "Folder")
public class Folder implements java.io.Serializable {
@EmbeddedId
private FolderId id;
@OneToOne
@MapsId("folderId")
private FolderObject folderObject;
}
FolderObjectID实体
@Entity @Table(name = "FolderObjectID")
public class FolderObjectID implements java.io.Serializable {
@Id
private long folderObjectId;
@OneToOne(mappedBy = "folderObject")
@JoinColumn(name = "folderObjectId")
private Folder folder;
}