Problem in JPA-Mapping
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开发者_JS百科 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;
}
精彩评论