I have some experience with OOP (Java, C#) and RDBs, but very little exposure to web programming. I am trying to understand what problem object persistence and ORM solves. Of course, I am familiar with the need for data persistence, but I have never encountered a need for object persistence.

I am not asking about the process of persisting an object to a database and resurrecting it later. I am not asking about why ORM frameworks are useful for doing this or a pain in the butt for doing this. I am particularly interested in how the need arises to map/persist relationships between objects.

I have seen many examples of persisting POJOs to a database, but the examples all seem to be for very simple objects that are essentially nothing more than records anyway: a constructor, some private fields, and getter/setter methods. This example:


offers such an example, but goes on to discuss the mismatch issues of granularity, inheritance, identity, associations, and navigation, which are not motivated by the example.

If someone could offer a toy example of an instance where, say, an inheritance relationship needs to be persisted, I would be grateful. This might be blindingly obvious for anyone who has already encountered this situation but I have not and a great deal of searching and reading has not turned up any examples.