JPA映射中的问题 [英] Problem in JPA-Mapping

查看:107
本文介绍了JPA映射中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库表如下所示,我想知道如何为这种类型的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_DateEnd_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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆