How do I use @IdClass with JPA Repository?

杀马特。学长 韩版系。学妹 提交于 2021-02-07 09:59:18

问题


I've been using a Spring JPA Repository interface to persist objects, and it works great! But how do I use it when the @Entity defines an @IdClass? The class is not embedded, but the fields are part of the object. Is it expected I should create findBy methods that name all the composite fields? Or is there a way to create a findById and pass the PK class?


回答1:


Nevermind - I found what I was missing. I was extending org.springframework.data.repository.Repository when what I really wanted was org.springframework.data.jpa.repository.JpaRepository. It has a builtin method for findOne which accepts the PK class.



来源:https://stackoverflow.com/questions/36501986/how-do-i-use-idclass-with-jpa-repository

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!