Home @Embeddable with @ManyToOne
Reply: 0

@Embeddable with @ManyToOne

user1444
1#
user1444 Published in August 14, 2018, 8:27 am

Imagine following classes

@Embeddable
class A {
    @ManyToOne
    public B classB;

    ...
    public State someEnum;
}

@Entity
@Table(name = "TEST")
class B {
    public long id;
    //... some data


   @Embedded
   @AttributeOverrides({
        @AttributeOverride(
                name = "classB.id",
                column = @Column(name = "EMBEDDED1_ID")
        ),
        @AttributeOverride(
                name = "someEnum",
                column = @Column(name = "EMBEDDED1_SOMEENUM")
        )
   })
   public A embedded1;

   @Embedded
   @AttributeOverrides({
        @AttributeOverride(
                name = "classB.id",
                column = @Column(name = "EMBEDDED2_ID")
        ),
        @AttributeOverride(
                name = "someEnum",
                column = @Column(name = "EMBEDDED2_SOMEENUM")
        )
   })
   public A embedded2;
}

So I am expectingthe database table to look like

  • TEST
    • ID
    • ...
    • EMBEDDED1_ID
    • EMBEDDED1_SOMEENUM
    • EMBEDDED2_ID
    • EMBEDDED2_SOMEENUM

But if fails with:

Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: ClassB column: classB_id(should be mapped with insert="false" update="false")

Versions:

Hibernate: 5.2.12.FINAL JPA: hibernate-jpa-2.1-api

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.372372 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO