Why we need to implement Persistable?
Added by Adrian Gygax 8 months ago
Hi!
I like the idea of Hades very much but I think it's not very elegant that I have to implement the Persistable interface (because this ties my POJOs to Hades). Isn't the definition of the ID already given by JPA's @ID annotation, so Hades could just use this information?
Cheers
Adrian
Replies
RE: Why we need to implement Persistable?
-
Added by Oliver Gierke 7 months ago
Hey Adrian,
this discussion comes up every once and a while. I agree with you on the downsides of the interface. The crucial part to us is not the getId method but rather the isNew which we need in multiple places (deciding whether to call persist or merge on the entity manager, deciding which references to set in our auditing support). We could implement the null check implemented in AbstractPersistable as static utility method, too, but would fix the decision whhen to regard an entity as new this way. The current API leaves this decision to the implementor of the domain classes while not bothering with JPA API details. As we provide an interface it's really easy to get rid of it supposed you want to free your entities from Hades one day.
Again, I see your points but hope I could throws some light on how we see the tradeoff made.
Regards,
Ollie