PersistentClass.checkColumnDuplication fails for columns with same name but distinct tables. The work around is to change the column name of one of the two tables.
Entities
{code:java} @Entity @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class Pool { @Id @GeneratedValue private Integer id;
public Integer getId() { return id; }
public void setId(Integer id) { this.id = id; } }
@Embeddable public class PoolAddress { @Column(table = "POOL_ADDRESS") private String address; public String getAddress() { return address; }
public void setAddress(String address) { this.address = address; } }
@Entity @SecondaryTables({ @SecondaryTable(name="POOL_ADDRESS"), @SecondaryTable(name="POOL_ADDRESS_2") }) @Tables({ @org.hibernate.annotations.Table(appliesTo="POOL_ADDRESS", optional=true), @org.hibernate.annotations.Table(appliesTo="POOL_ADDRESS_2", optional=true, inverse = true) }) public class SwimmingPool extends Pool {
@Embedded private PoolAddress address;
@Embedded @AttributeOverride(name = "address", column = @Column(table = "POOL_ADDRESS_2")) private PoolAddress secondaryAddress;
public PoolAddress getAddress() { return address; }
public void setAddress(PoolAddress address) { this.address = address; }
public PoolAddress getSecondaryAddress() { return secondaryAddress; }
public void setSecondaryAddress(PoolAddress secondaryAddress) { this.secondaryAddress = secondaryAddress; }
} {code}
Fails with:
{code:java} Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: org.hibernate.test.annotations.inheritance.union.SwimmingPool column: address (should be mapped with insert="false" update="false") at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:870) at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:888) at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:884) at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:910) at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:642) at org.hibernate.mapping.UnionSubclass.validate(UnionSubclass.java:44) at org.hibernate.boot.internal.MetadataImpl.validate(MetadataImpl.java:347) at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:466) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:708) at org.hibernate.testing.junit4.BaseCoreFunctionalTestCase.buildSessionFactory(BaseCoreFunctionalTestCase.java:117) at org.hibernate.testing.junit4.BaseCoreFunctionalTestCase.buildSessionFactory(BaseCoreFunctionalTestCase.java:104) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.hibernate.testing.junit4.TestClassMetadata.performCallbackInvocation(TestClassMetadata.java:205) ... 11 more {code} |
|