1

I have Hibernate 5.2.10 version and hibernate-jpa-2.1-api with version 1.0.0.Final. I am using MairaDB as database. In persistance.xml, set the property hibernate.ejb.naming_strategy as DefaultComponentSafeNamingStrategy but still I receive the same error: Repeated column in mapping for entity. I do not want to use @attributeoverrides hibernate and I tried different methodes but still the same error. I want two or more embedded enities.

Thanks

1 Answer 1

1

You can't use DefaultComponentSafeNamingStrategy with Hibernate 5, because of it is an implementation of the old NamingStrategy interface from Hibernate 4.

As you probably know, Hibernate 5 uses two new interfaces ImplicitNamingStrategy and PhysicalNamingStrategy.

You can use this implicit naming strategy: org.hibernate.boot.model.naming.ImplicitNamingStrategyComponentPathImpl. You will need to set hibernate.implicit_naming_strategy property (not hibernate.ejb.naming_strategy).

For these entities

@Embeddable
public class AuthorInfo {

    @Column
    private String authorInfo;

    @OneToOne
    private Book bestBook;

}

@Entity
public class Book {

    @Id
    private Long pid;

    @Embedded
    private AuthorInfo firstAuthor;

    @Embedded
    private AuthorInfo secondAuthor;

}

it creates this schema

create table Book (
        pid bigint not null,
        firstAuthor_authorInfo varchar(255),
        secondAuthor_authorInfo varchar(255),
        firstAuthor_bestBook_pid bigint,
        secondAuthor_bestBook_pid bigint,
        primary key (pid)
)

Unit test to check a schema: TwoEmbeddedStrategyTest.java

Sign up to request clarification or add additional context in comments.

5 Comments

I used annotation @column and used this org.hibernate.boot.model.naming.ImplicitNamingStrategyComponentPathImpl and did not work but after removing annotations it worked.
@Elhamo I have checked this with Hibernate SessionFactory, not with PersistentContext. It can be a reason, but I am not sure. You could just miss something.
@v.ladynev My experience is that if you use the org.hibernate.boot.model.naming.ImplicitNamingStrategyComponentPathImpl strategy then @Column is ignored (specifically the name value). Is there a way to use this strategy while preserving the use of @Column? This problem might be what @Elhamo was describing.
@mbmast @Column is ignored with PhysicalNamingStrategy. It shouldn't be ignored with ImplicitNamingStrategy, as I can remember.
PhysicalNamingStrategy only contains information on the column. How am I to detect if the naming applies to a certain field of a certain class or embeddable type. Containz zero useful information. Just column name through identifier.getText().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.