I created the following mapping configuration:
EntityA.java
~~~
@Entity
@Table(name="TableA")
@SecondaryTables({@SecondaryTable(name = "TableB")})
public class EntityA {
@Id
Integer id;
@Embedded
EmbeddableA embed;
// getters and setters
}
~~~
EmbeddableA.java
~~~
@Embeddable
public class EmbeddableA {
@Embedded
@AttributeOverrides({@AttributeOverride(name = "embedAttrB" , column = @Column(table = "TableB"))})
EmbeddableB embedB;
String embedAttrA;
// getters and setters
}
~~~
EmbeddableB.java
~~~
@Embeddable
public class EmbeddableB {
String embedAttrB;
// getters and setters
}
~~~
Which created the following Table structures:
----------- -------------
----------- -------------
id |
|
id |
embedAttrA |
|
embedAttrB |
----------- -------------
After trying to persist, the following Exception is thrown:
Caused by: org.hibernate.exception.SQLGrammarException: Unknown column 'embedAttrB' in 'field list'
To make this work, I moved EmbeddableB directly into EntityA, with the original AttributeOverride annotations. Now that the @Embeddables aren't nested, EmbeddableB persists to TableB, as was the original intent. It appears that the table attribute in the AttributeOverride is not being applied @Embeddable classes are nested, even though the column attribute is applying properly and we get an error if TableB is not setup as a secondary table in the entity.
|