Hibernate/persistence without @Id

后端 未结 9 856
梦谈多话
梦谈多话 2020-11-28 09:07

I have a database view that yields a result set that has no true primary key. I want to use Hibernate/Persistence to map this result set onto Java objects. Of course, becaus

9条回答
  •  不知归路
    2020-11-28 09:59

    According to Hibernate user guide, using the pk is recommended so even if you are working with the existing project that doesn't contain the pk in the database side, you can add the pk column to the related database table and map it with the Java entities.

    The hibernate recommendation was like that:

    We recommend that you declare consistently-named identifier attributes on persistent classes and that you use a wrapper (i.e., non-primitive) type (e.g. Long or Integer).

    For more detail about pk and Hibernate mechanism, please visit here

提交回复
热议问题