0

I have some experience with OOP and RDBs, but very little exposure to web programming. I am trying to understand what non-trivial types of problems are solved by ORM. Of course, I am familiar with the need for data persistence, but I have never encountered a need for persisting relationships between objects, a situation which is indicated in many online articles about ORM.

I am not asking about the process of persisting a POJO to a database and restoring it later. Nor am I asking about why ORM frameworks are useful -- or a pain in the butt -- for doing so. I am particularly interested in how the need arises to persist and restore relationships between objects.

In various documentation, I have seen many examples of persisting POJOs to a database, but the examples have all been for only very simple objects that are essentially nothing more than records anyway: a constructor, some private fields, and getter/setter methods. The motivation for persisting such an "object-record" seems obvious and trivial. This example:

Hibernate ORM Tutorial

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

If someone could offer a toy example of an instance where, say, the need arises to persist an inheritance relationship, 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 have not turned up any examples.

migrated from stackoverflow.com Jun 1 '14 at 17:19

This question came from our site for professional and enthusiast programmers.

  • "Where the need arises to persist an inheritance relationship"? Well, it arises whenever you have a domain model with inheritance in it, and you need to persist the whole shebang. Are you really asking how to represent inheritance in SQL schemas? In that case, see programmers.stackexchange.com/questions/160473/… – Kilian Foth Jun 1 '14 at 19:54
  • It was the need to persist the whole shebang that was eluding me. I wasn't thinking through the specifics of restoring a child class as an object. Obviously, to instantiate a child you need to know that you must also instantiate the parent. I was thinking about this entirely too abstractly. Thanks for taking the time to reply. – Schemer Jun 2 '14 at 18:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.