Hibernate embeddables: component property not found

后端 未结 1 1032
春和景丽
春和景丽 2020-12-11 06:37

I\'m trying to use JPA @Embeddables with Hibernate. The entity and the embeddable both have a property named id:

@MappedSuperclass
         


        
相关标签:
1条回答
  • The naming strategy configuration has changed. The new way as per the Spring Boot documentation is this:

    spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyComponentPathImpl
    

    Also, you must not use @Id within an @Embeddable. I thus created a seperate @MappedSuperclass for embeddables:

    @MappedSuperclass
    public abstract class A {
        @Id
        @GeneratedValue
        long id;
    }
    
    @MappedSuperclass
    public abstract class E {
        @GeneratedValue
        long id;
    }
    
    @Embeddable
    public class B extends E {
    
    }
    
    @Entity
    public class C extends A {
        B b;
    }
    

    This way, the table C has two columns id and b_id. The downside is of course that A and E introduce some redundency. Comments regarding a DRY approach to this are very welcome.

    0 讨论(0)
提交回复
热议问题