问题
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