Immutable entities with Ebean #2781
Replies: 2 comments 1 reply
-
With Ebean, entities do not need setter methods or any mutator methods. Additionally entities do not require default constructors. So that also means that Ebean also supports using java record types as entities. That is, we can model the entities as non-mutating / no setters. Also note that with Ebean we explicitly specify which entities are persisted by explicitly passing them to save(), update() etc which is unlike JPA where mutated entities are persisted automatically (1). So these 2 things combined mean we have not required an If we don't want to model the entity without setters and don't want to trust ourselves not to save() or update() it then we could add a BeanPersistController with preUpdate() returning false and use that to either ignore updates or throw an exception. I have not heard of people doing this, but a preUpdate() returning false would match the Does that answer the question or is there a more specific scenario that you have in mind? Cheers, Rob. (1) where mutated entities are persisted automatically ... is referred to as "transparent persistence". Note that Ebean has an experimental feature that also does this - see |
Beta Was this translation helpful? Give feedback.
-
Now that all said, having "Insert only tables" or "Append only tables" is an fairly common scenario - e.g. IoT. So making that scenario explicit and easy has some value. Hmmm. |
Beta Was this translation helpful? Give feedback.
-
Recently I was move one of my app from hibernate JPA to Ebean and in one of my entities I had been
@Immutable
annotation.I searched on many topics and I can't found answer with indicate a similar behavior on Ebean. He has anything to lock update in entities?
Beta Was this translation helpful? Give feedback.
All reactions