In Google's RequestFactory
tutorials, they recommend putting my persistence logic (in my case, Hibernate) inside the Entity classes. Then they pose the question: "What if you don't want to implement persistence code in an entity itself?" and proceed to explain an alternate method.
My question: which is better, putting persistence logic inside the Entity class, or keeping all persistence logic in a separate class?
Any info is appreciated, thanks.
-tjw
Putting the persistence code in an entity itself is an Active Record Pattern approach while keeping all persistence logic in a separate class is the Repository Pattern approach. You can use the keyword repository pattern vs activerecord
to search more information about your questions.
For example ,active record pattern has a criticism about its testability without a database , you can refer to this for more info .
For me , I prefer the Repository Pattern more as it is testable and I don't like persistence codes and domian business logic are mixed in one class which violates the emphasis on separation of concerns.