JPA Mapping Error -not provided sufficient metadata in your id class
I am trying to do mapping in JPA.
@Entity
public class Auction {
@Id
private Integer auctionId;
@OneToMany(mappedBy="auctionId")
@MapKey(name="auctionParamId")
private Map<AuctionParam, AuctionParamValue> values;
}
@Entity
public class AuctionParam {
@Id
private Integer auctionParamId;
private String description;
}
@Entity
public class AuctionParamValue {
@EmbeddedId
private AuctionParamValuePK pk;
private String value;
}
@Embeddable
public class AuctionParamValuePK {
@ManyToOne
@JoinColumn(name="auctionId")
private Auction auction;
@ManyToOne
@JoinColumn(name="auctionParamId")
private AuctionParam auctionParam;
}
Showing an error:-
.Error-Details:-Exception Description: Entity [class com.eaportal.domain.AuctionPar开发者_开发技巧amValue]
uses [class com.eaportal.domain.AuctionParamValuePK] as embedded id class whose access-type has been determined as [FIELD]. But [class com.eaportal.domain.AuctionParamValuePK] does not define any [FIELD]. It is likely that you have not provided sufficient metadata in your id class [class com.eaportal.domain.AuctionParamValuePK].
If you come up with a solution please let me know.
Thanks in Advance Tushar
You cannot use an EmbeddedId with relationships. Use an IdClass.
@Entity
@IdClass(AuctionParamValuePK.class)
public class AuctionParamValue {
@Id
@ManyToOne
@JoinColumn(name="auctionId")
private Auction auction;
@Id
@ManyToOne
@JoinColumn(name="auctionParamId")
private AuctionParam auctionParam;
@Basic
private String value;
}
public class AuctionParamValuePK {
private int auction;
private int auctionParam;
}
I think there are some errors in your Auction
class. This is how I think it should look
@Entity
public class Auction {
@Id
private Integer auctionId;
@OneToMany(mappedBy="auction") // not auctionId
@MapKey(name="auctionParam") // not auctionParamId
private Map<AuctionParam, AuctionParamValue> values;
}
(The annotation values have to correspond with fields (or properties), not with columns)
精彩评论