13
我有課的錢這是一個@Embeddable嵌套嵌入 - AttributeOverride來爲嵌入內嵌入
@Embeddable
public class Money implements Serializable, Comparable<Money> {
@Column(name = "amount", precision = 15, scale = 2)
private BigDecimal amount;
}
當我useit內部實體,一切工作正常多的時間。例如
@Entity
public class SomeEntity implements Serializable {
@Embedded
@AttributeOverride(name = "amount", column = @Column(name = "entry"))
private Money entryValue;
@Embedded
@AttributeOverride(name = "amount", column = @Column(name = "leave"))
private Money leaveValue;
}
上面的代碼完美地工作。
現在問題出現時,我有另一個@Embeddable,我想在其中有Money實例,並且@Embeddable多次被實體使用。例如:
嵌入式
@Embeddable public class ReportCostValues implements Serializable { @Embedded @AttributeOverride(name = "amount", column = @Column(name = "covered_by_grant")) private Money coveredByGrant; @Embedded @AttributeOverride(name = "amount", column = @Column(name = "own_resources")) private Money foundedFromOwnResources; @Embedded @AttributeOverride(name = "amount", column = @Column(name = "personal_contribution")) private Money personalContribution;
實體
@Entity public class ReportCostEntity implements Identifiable<Long>, Serializable { @Id private Long id; @Embedded private ReportCostValues contracted; @Embedded private ReportCostValues current; @Embedded private ReportCostValues previousReport;
此代碼上面將不起作用。任何想法如何解決這個問題?
它的工作,非常感謝你! – 2012-03-25 20:07:26
@PaulSzulc歡迎您 – 2012-03-26 06:20:23