Is it ok for entities to access repositories?

it’s not a horrible violation of DDD it’s a horrible violation of… well… it’s just plain horrible (i say this tongue in cheek) :). First off, your entity becomes dependent on having a repository… that’s not ideal. Ideally you’d want to have your repository create the Person and then assign it everything it needs to … Read more

How are Spring Data repositories actually implemented?

First of all, there’s no code generation going on, which means: no CGLib, no byte-code generation at all. The fundamental approach is that a JDK proxy instance is created programmatically using Spring’s ProxyFactory API to back the interface and a MethodInterceptor intercepts all calls to the instance and routes the method into the appropriate places: … Read more

What’s an Aggregate Root?

In the context of the repository pattern, aggregate roots are the only objects your client code loads from the repository. The repository encapsulates access to child objects – from a caller’s perspective it automatically loads them, either at the same time the root is loaded or when they’re actually needed (as with lazy loading). For … Read more