The presence of a nested class MultiLanguageText:
@Embeddable public class MultiLanguageText { @Field private String textDe; @Field private String textFr; @Field private String textIt;
And another class that uses this class twice:
@Entity(name = "T_AnotherClass") public class AnotherClass{ @Id @GeneratedValue private long key; @Embedded private MultiLanguageText name; @Embedded private MultiLanguageText description;
The fields were perfectly translated into "name_textDe", "description_textDe", "name_textFr", etc. with spring version 1.2.7.RELEASE.
However, to store LocalDate, I wanted to switch to Hibernate 5. I followed the process described here: https://github.com/spring-projects/spring-boot/issues/2763#issuecomment-154419889
The process worked fine, but the translation of the embedded fields stopped working *. I tried different implicit_naming_strategy and physical_naming_strategy but didn't work.
If I annotate the fields as follows, it works, but the process is somewhat cumbersome:
@Embedded @AttributeOverrides({ @AttributeOverride(name = "textDe", column = @Column(name = "name_textDe", length = MultiLanguageText.MAX_TEXT_LENGTH)), @AttributeOverride(name = "textFr", column = @Column(name = "name_textFr", length = MultiLanguageText.MAX_TEXT_LENGTH)), @AttributeOverride(name = "textIt", column = @Column(name = "name_textIt", length = MultiLanguageText.MAX_TEXT_LENGTH)), }) private MultiLanguageText name;
* Doesnβt work means that I get an exception something along the lines (since now the field is displayed without the field prefix and therefore the field exists twice):
Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: AnotherClass column: textDe (should be mapped with insert="false" update="false") at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:764) at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:782) at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:778) at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:804) at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:539) at org.hibernate.mapping.RootClass.validate(RootClass.java:265) at org.hibernate.boot.internal.MetadataImpl.validate(MetadataImpl.java:329) at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:443) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879) ... 48 more