Search code examples
javaooprelational

What is the best way to convert relational to object oriented?


Since I learned about RDBMS, I started thinking in the relational model and less in the object oriented. Now I'm having trouble trying to store and query data in Java data structures.

I want to write an application that has entity sets that relate to each other so I made each entity its own class. The attributes for each entity are the instance variables. Okay I think we're good so far. Title and Game are all entities. Game ISA Title so Title should be the parent class and Game should inherit from Title (think of Game as the physical copy and Title as the name of the Game).

I have a set of games in my main class and I can iterate through if I want to find a specific Game. How would I find a specific Title? I don't have a set of titles because Title is inherited so I would assume I should just iterate through games and when I find a name of a title, add it to a set so that I only get unique titles back.

Game is mutable (isBought can change) so is using a Set a bad idea? What is the best way to create Entity sets in Java? Using a Map instead of a set to map an id to an object?


Solution

  • Fixing the object-relational gap is not an easy task. There are ORM (object-relational mapping) frameworks that do that. But they have some learning curve. Hibernate and EclipseLink are two implementations of the ORM standard in Java - JPA (java persistance API).