Life Cycle Events #1637
evanchooly
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've been working on and with Morphia for a long time now. The lifecycle events have always felt ... off to me. I actually removed two events with 2.0 and no one seemed to notice or care. On the other hand, I have gotten a number bug reports and support questions around them so they are clearly used. But I have a question and would like some input from the community. Currently there are 4 events: pre/post persist/load. My gut tells me that's two too many and that's partly driven by the implementation details.
In my mind, all that's really needed are
prepersist
andpostload
. That isprepersist
: an event with the serialized document and entity model right before the document is handed off to the driver to be persisted in the database.postload
: an event containing the document fetched from the database and the entity model.Having the document in both cases allows for developers to tweak the document in various ways and having the entity model allows access to the mapped metadata about the entity (document field names, any annotations, etc.). The most common use I can think of would be, say, encrypting or decrypting certain fields at the database boundary to keep certain values secure. I'm sure there are many uses that I'm not thinking of. And that's where I would love your input.
I would love to hear from you which lifecycle events you actively use and how you use them. I would also love to hear if any users make use of the global interceptors to apply lifecycle events across the board without having to map each entity accordingly. I think there are some simplicity gains to be had by rethinking how Morphia defines and uses these events. Unfortunately, the decisions and design of these events predate my involvement with the project so I'm not privy to those details. I would love your input, though.
So what have you got?
Beta Was this translation helpful? Give feedback.
All reactions