So in a recent project (a small internal tool), I want to experiment with not using an ORM tool which we typically use in all our projects. The reason is that I particularly aren't a fan of them specially in complex projects with complex object hierarchies and relationships. Using an ORM it becomes difficult to debug performance issues and other issues arising from a lot of things that the ORM library might do under the covers to "optimize".
So I was thinking of a way to lazy load certain properties of objects when I don't have the help of an ORM tool. Suppose an example:
class Student {
private List<Course> courses;
public List<Course> getCourses() {...}
public void setCourses(List<Course> courses) {...}
}
So in this case we put "courses" lazily. So I want a way to differentiate between a scenario in which the "courses" has not been loaded from the database and when "courses" is actually null even after fetching from the DB.
What are the typical ways in which I can achieve it. I was thinking that probably associate a special empty object of type "Course" denoting that actually no data exists in the DB. And the java null would mean that the data is not fetched from the DB. But this would break abstraction a bit in the sense that the getter for such lazy properties need to make the decision to accessing the DAO to getting the data.