Difference using @Id and @EmbeddedId for a compound key

前端 未结 2 1812
暗喜
暗喜 2020-12-29 05:23

I\'ve created an entity that uses @Id to point to an @Embeddable compound key. Everything I believe works fine as is. However, after switching @Id to @EmbeddedId everythin

2条回答
  •  时光说笑
    2020-12-29 06:14

    It's too late for this answer but in case it helps.

    I referred hibernate docs Hiberate 3.5 annotations reference whereby there is the difference that with @EmbeddedId you can skip annotating the entity class @Embeddable but with @Id its required.

    I tried using @Id without @Embeddable it gives exception:

    org.hibernate.mapping.SimpleValue cannot be cast to org.hibernate.mapping.Component

    Just this and no extra info like the field or class name.

    Well this behavior is as of Hibernate 4; I dont know about other JPA providers. I will test a few and update post accordingly if there are any more findings.

    I hope this helps someone!

提交回复
热议问题