JPA映射错误 - 未在您的id类中提供足够的元数据

时间:2011-01-19 07:00:46

标签: java spring jpa eclipselink jpa-2.0

我正在尝试在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;

}

显示错误: -

  

.Error-Details:-Exception描述:   实体[类   com.eaportal.domain.AuctionParamValue]
  使用[类   com.eaportal.domain.AuctionParamValuePK]
  作为嵌入式id类
  其访问类型   已被确定为[FIELD]   但   [类   com.eaportal.domain.AuctionParamValuePK]
  没有定义任何[FIELD]。它是   可能你没有提供
  您的id类中有足够的元数据   [类   com.eaportal.domain.AuctionParamValuePK]。

如果您想出解决方案,请告诉我。

先谢谢 图莎尔

2 个答案:

答案 0 :(得分:2)

您不能将EmbeddedId与关系一起使用。使用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;

}

答案 1 :(得分:0)

我认为您的Auction课程中存在一些错误。这就是我认为应该看起来的方式

@Entity
public class Auction {

    @Id
    private Integer auctionId;

    @OneToMany(mappedBy="auction") // not auctionId
    @MapKey(name="auctionParam") // not auctionParamId
    private Map<AuctionParam, AuctionParamValue> values;

}

(注释值必须与字段(或属性)对应,而不是与列对应)