-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PrePersist / PostPersist / ... Semantics for Enitites #2
Comments
I would do an single interface per method. I don't really like having a bunch of empty method bodies. In AbstractDao, the instanceof operator could be used to determine if the entity should receive a specific callback. This would easily allow for superclasses to define callbacks with out requiring configuration during generation. If a user would like the entity itself to implement the interface, they could use the methods on the entity generation object "implementsPostLoad", "implementsPrePersist", etc. After the TX commit seems reasonable to me, however, it could also make sense to do it when the identityScope is updated.. which I think is straight after the SQL statement. |
OK, single interface per method sounds good. I'd say, let's go with the simple solution and do the callback after the SQL statement (and identity scope). Let's don't worry about TXs for now - we could implement a more complex TxListener at a later point, too, which collects all updated, inserted, and deleted entities. Failing TXs are a nasty subject with ORMs.... |
Actually, I'm not totally convinced about the before or after TX topic. Have to give this a little more thought... |
After would almost certainly be best... however, I haven't looked through your code to see how difficult it would be. |
Here's how rails does it: From what I read, they essentially do everything right before and after the SQL statements. post* methods still have the ability to cancel the transaction. |
I was just looking at JPA (http://download.oracle.com/otndocs/jcp/persistence-2.0-fr-eval-oth-JSpec/)... Exceptions in callback/listeners seem always to rollback the TX (chapter 3.5), which might rule the "after-TX" option out. Still wondering why JPA does it after the individual calls. Maybe that's not a bad option after all. |
So thats two widely used mature ORMs.. maybe that's just how it's done It would sure be easier in any case. Though I like doing things the best way.. not the easiest. |
This is also interesting: "The PreUpdate and PostUpdate callbacks occur before and after the database update operations to entity data respectively. These database operations may occur at the time the entity state is updated or they may occur at the time state is flushed to the database (which may be at the end of the transaction)." So, JPA doesn't even define the exact timing. We don't want to be better than JPA. ;) It seems we can stick to the simple solution. Just want to wait another day to see if something comes up. Also, maybe @yigit has an opinion on this? |
we needed similar functionality in our Path fork and the way I implemented it is having an empty method in base class could have a bunch of empty methods for each listener. when needed in code, custom To give a full example,
after execute insert is run in I agree transactions are just too complex to handle properly. |
Callbacks for the entity class itself to organize its data.
The JPA equivalent would be the following annotations (http://en.wikibooks.org/wiki/Java_Persistence/Advanced_Topics#Events), which we should should adapt:
Thoughts on how to implement:
Open questions:
This tickets relates to #44 (external listeners).
The text was updated successfully, but these errors were encountered: