@Embedded课程在Hiberante的聚合



i在这些类中有一个情况,其中第一个由@embedded字段包含,然后第三次包含第二次,是两个不同的@embedded字段:

@Embeddable
public class StorageSize {
  // ...
  @Column(nullable = false)
  private Long size;
  // ...

@Embeddable
public class StorageSizeTBPerMonth {
  // ...
  @Embedded
  private StorageSize storage = new StorageSize();
  // ...

@Entity
public class StorageRange {
  // ...
  @Embedded
  @AttributeOverrides({ @AttributeOverride(name = "size", column = @Column(name ="storage_low")) })
  private StorageSizeTBPerMonth limitLow;
  // ...
  @Embedded
  @AttributeOverrides({ @AttributeOverride(name = "size", column = @Column(name = "storage_high")) })
  private StorageSizeTBPerMonth limitHigh;

,当我尝试使用上面的类运行代码时,我会得到异常

Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: com.mycompany.data.model.StorageRange column: size (should be mapped with insert="false" update="false") at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:676) at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:698) at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:694) at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:694) at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:720) at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:474) at org.hibernate.mapping.RootClass.validate(RootClass.java:236) at org.hibernate.cfg.Configuration.validate(Configuration.java:1193) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1378) at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:954) at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:892) ... 24 more

当我在@attributeoverride中用"存储"代替" size"。

有什么想法如何拉动模型?如果可能

没有属性sizeStorageSizeTBPerMonth中覆盖。它确实具有具有属性size的嵌入式字段storage。这就是storage.size要走的原因:

@Embedded
  @AttributeOverrides({ @AttributeOverride(name = "storage.size", column = @Column(name ="storage_low")) })
  private StorageSizeTBPerMonth limitLow;
  // ...
  @Embedded
  @AttributeOverrides({ @AttributeOverride(name = "storage.size", column = @Column(name = "storage_high")) })
  private StorageSizeTBPerMonth limitHigh;

在JPA 2.0规范中,以下单词被告知:

要在多个嵌入层的层面上覆盖映射,必须在名称元素中使用点("。")符号表格,以指示嵌入式属性中的属性。DOT符号使用的每个标识符的值是相应嵌入式字段或属性的名称。

相关内容

  • 没有找到相关文章

最新更新