Problem in JPA-Mapping

泪湿孤枕 提交于 2019-12-08 07:35:27

问题


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

Table Name : auction with primary key as auction_id

Table Name : *auction_param* with primary key as auction_param_id

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 

Table Name : auction_param_values

It stores the actual values of that parameters related to Auction.

Table looks like:-

auction_id | auction_param_id | auction_param value | 

   1       |      2           |      2011-01-15     | 

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.


回答1:


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;

}


来源:https://stackoverflow.com/questions/4688709/problem-in-jpa-mapping

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!