一对一弱实体映射JPA [英] One to One Weak Entity Mapping JPA
本文介绍了一对一弱实体映射JPA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个实体类
@Entity
Class Search
{
@Id
private Long SearchID;
private String Type;
}
和另一个实体类(SearchResults是一个弱实体,它依赖于搜索类为其主键
and another Entity Class ( SearchResults which is a weak Entity that depends on Search Class for its Primary Key
@Entity
Class SearchResults
{
@???
private Long SearchID;
}
在弱实体"SearchResults"中,应该使用什么注释来将搜索"实体类的搜索ID"分配为主键
What annotation should i use to assign "SearchID" of "Search" Entity class as my primary key in my weak Entity " SearchResults"
推荐答案
使用JPA共享主键的概念,可以按如下所示映射关系:
Using the JPA concept of Shared Primary Key, you can map your relationship as follows:
您的主要班级:
@Entity
public class Search {
@Id
private Long searchID;
private String type;
}
具有单个属性的派生标识符
@Entity
public class SearchResults {
@Id
@OneToOne
@JoinColumn(name = "SEARCHID")
private Search search;
}
具有共享映射的发送者标识符
@Entity
public class SearchResults {
@Id
private Long searchID;
@MapsId
@OneToOne
@JoinColumn(name = "SEARCHID")
private Search search;
}
此处全文: http ://vard-lokkur.blogspot.com.br/2014/05/onetoone-with-shared-primary-key.html
这篇关于一对一弱实体映射JPA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文