0

I have spring boot application with JPA and MySQL. The table is already created and data are present. From the spring boot application, we need to create two API - get a particular record using id and get all the records. I created a model class but confused with usage of @Entity. Because I'm not going to insert/delete a record from the database. I want to use only for select the record.

For Select query (findBy), do we need to use @Entity annotation at the top of model class?

Kumaresh Babu N S
  • 1,648
  • 5
  • 23
  • 39

1 Answers1

1

Yes, you would need to use @Entity to mark your model class, this tells JPA that your class is used for mapping to and from a database table. If you want to make sure that you don't accidentally overwrite the data, you could implement a check via @EntityListener, as described in this answer.

Don Ho
  • 1,289
  • 10
  • 18