How to make an Entity read-only?

后端 未结 9 1283
情歌与酒
情歌与酒 2020-12-03 00:43

What is the proper way to make an Entity read-only with JPA ? I wish my database table to never be modified at all programmatically.

I think I understand that I sho

9条回答
  •  旧巷少年郎
    2020-12-03 01:00

    A solution is to use field based annotation, to declare your fields as protected and to propose only public getter. Doing so, your objects can not be altered.

    (This solution is not entity specific, it is just a way to build immutable objects)

提交回复
热议问题