JPA映射中的问题 [英] Problem in JPA-Mapping
问题描述
我的数据库表如下所示,我想知道如何为这种类型的JPA映射 表格,尤其是对于没有主键ID的Auction_param_values
I have a situation where my DB tables are like below, I am wondering how to have JPA mappings for this kind of tables , espacially for the auction_param_values which do not have primary key ID
表名: 拍卖 ,主键为Auction_id
Table Name : auction with primary key as auction_id
表名: * auction_param * ,主键为Auction_param_id
Table Name : *auction_param* with primary key as auction_param_id
表AUCTIO_PARAM
用于存储Start_Date
,End_Date
等参数的详细信息.
Table AUCTIO_PARAM
is used stores the details of parameters such as Start_Date
,End_Date
etc.
auction_param_id | auction_param_desc
1 | start date
2 | end_date
表名称: auction_param_values
它存储与Auction
相关的参数的实际值.
It stores the actual values of that parameters related to Auction
.
表格如下:-
auction_id | auction_param_id | auction_param value |
1 | 2 | 2011-01-15 |
实体类将如何查找auction_param_values
?关于我们如何设计有什么建议吗
支持JPA的架构(我们使用Eclipselink作为提供程序).
How will the entity class look for the auction_param_values
? is there any pointer on how we can design
the schema to support JPA (we are using Eclipselink as a provider).
如果需要,我可以提供更多详细信息.
If require I can provide more details.
推荐答案
不知道我是否理解正确,但这可能是您需要的:
dont know if I understood correctly but this might be what you need:
@Entity
public class Auction {
@Id
private Integer id;
@OneToMany(mappedBy="pk.auction")
@MapKey(name="pk.auctionParam")
private Map<AuctionParam, AuctionParamValue> values;
}
@Entity
public class AuctionParam {
@Id
private Integer id;
private String description;
}
@Entity
public class AuctionParamValue {
@EmbeddedId
private AuctionParamValuePK pk;
private String value;
}
@Embeddable
public class AuctionParamValuePK {
@ManyToOne
@JoinColumn(name="auction_id")
private Auction auction;
@ManyToOne
@JoinColumn(name="auctionparam_id")
private AuctionParam auctionParam;
}
这篇关于JPA映射中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!