Reputation: 335
I have a class named Genre (a @Entity), having only one field "name" (which is also id), in my Spring Boot application. It works fine, but now I realized - maybe I can't use the CRUDRepository to update a genre...
Since if I send in an altered Genre to genreRepository.save() - how can it find it? Can I make my own query to update it by name? Or must I add a new Id-field to the entity?
Greetings Val
Upvotes: 1
Views: 289
Reputation: 433
First thing is I advice you to reconsider your design since it only contains one column "name", to my understanding normally you might not want to use the string as a primary key, I think its better to use a separate column such as "ID" which will uniquely identify each row in a table, when you do that there are bunch of options provided in the spring boot and then using Spring CRUD Repository make more sense
Upvotes: 1
Reputation: 1
As answered already in this Question (How to use spring Repository without @Id?) JPA requires that every entity has an ID.
Upvotes: 0