【发布时间】:2012-03-23 19:44:27
【问题描述】:
我有一个 @Embeddable 类的 Money
@Embeddable
public class Money implements Serializable, Comparable<Money> {
@Column(name = "amount", precision = 15, scale = 2)
private BigDecimal amount;
}
当我在实体内多次使用它时,一切正常。例如
@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;
上面的这段代码不起作用。任何想法如何解决这个问题?
【问题讨论】:
标签: hibernate jpa embeddable