I have a situation with these classes, where 1st is contained by 2nd as @Embedded field, and then 3rd is containing 2nd two times as two different @Embedded field :
@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;
And when I try to run the code with classes above I get the exception
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
It's the same when I substitute "size" with "storage" in @AttributeOverride.
Any idea how to pull model like this one? If possible I would avoid creating new entities and keep both StorageSize and StorageSizeTBPerMonth as embeddable classes.