0

I'm currently working on the project where ALL entities have @GeneratedValue for their id fields. But some of those entities are only read, some are only read and updated and there's no chance that there will be some inserts needed.

So does @GeneratedValue really make sense for entities which will never be inserted? I mean can I just remove all of them and it will be fine?

1 Answers1

1

no there is no need when your application is read-only, but it is safer to have one since you are uncertain that in future you may be updating entries, but for other entities which you are certain that it is read only then there is no need to add it. check (How to make an Entity read-only?) for better making entities read only

Mohammed Fataka
  • 150
  • 1
  • 8
  • Thanks. Read-only is a bit over engineering in my case. I just wanted to be sure that by removing existing annotations I don't lose any functionality on updates or deletes. – Arsen Nykytenko Apr 08 '23 at 23:44
  • 1
    sure updates or deletes are managed by JPA or Crud so no worries on that, regarding making fields read-only i suggest the simplest way to go is to annotate the ids of entities that are updatable with `@Column(insertable = false, updatable = false) ` – Mohammed Fataka Apr 08 '23 at 23:48