0

首先,我有两个实体文件夹和 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 列的两个实体上的一对一关系。不幸的是,我收到错误消息说我在文件夹实体上有一个损坏的列。

有人可以在这件事上启发我。谢谢。

4

1 回答 1

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;
}
于 2013-04-04T12:29:42.217 回答