So, I\'ve noticed that I definitely have a tendency to pattern my Spring/Hibernate stack objects like this:
I think that there is a simple refactoring pattern that will solve your problem.
This will help evolve you towards a richer domain model. It also preserves the Single Responsibility Principle since all your DB-dependent code remains in the FooService implmentations and helps you migrate the business logic from FooService to Foo. In you want to switch your back-end to another DB or in-memory or mock (for testing) you don't need to change anything but the FooService layer.
^ I am presuming that FooService does DB calls that would be too slow to do from an ORM like selecting the most recent Foo that shares property X with a given Foo. That is how most I've seen work.
Example
Instead of:
class Controller{
public Response getBestStudentForSchool( Request req ){
Student bestStudent = StudentService.findBestPupilForSchool( req.getParam( "schlId" ).asInt() );
...
}
}
You'll move towards something like this:
class Controller{
public Response getBestStudentForSchool( Request req ){
School school = repo.get( School.class, req.getParam( "schlId" ).asInt() );
Student bestStudent = school.getBestStudent();
...
}
}
Which I will hope you will agree already seems richer. Now you are making another database call, but if you keep the School cached in session the penalty is neglible. I'm afraid that any truly OOP model will be less efficient than the anemic model you are using, but the reduction of bugs through code clarity should be worth it. As always, YMMV.