0

I'm wondering if there's a general term used for objects that map exactly to data tables? E.g., a user and an article objects could map directly to user and article tables in a db, with each db field corresponding to a class variable...

JDelage
  • 13,036
  • 23
  • 78
  • 112

2 Answers2

5

They are referred to as Entities in JPA specification.

Vikdor
  • 23,934
  • 10
  • 61
  • 84
  • Is that used in non Java apps, e.g., in a PHP application? – JDelage Sep 12 '12 at 19:11
  • In case you are referring to JPA, no, it is only for java apps. If you are looking for ORM frameworks to manage entities in your PHP app, then this should help - http://stackoverflow.com/questions/2605074/anything-similar-to-hibernate-in-php. – Vikdor Sep 12 '12 at 20:11
2

They are usually called entities, but entities in general don't need to map 1:1 to DB tables. However, what you describe is known as Active Record pattern.

Also, please note that there is very rarely an exact 1:1 mapping between object model and DB:

  • many-to-many relationships are usually implemented with third table in the DB but are usually mapped to only 2 classes with direct associations in the object model (if relation doesn't have additional attributes)
  • class inheritance can be modeled in 3 different ways in the DB with 1, N or N + 1 tables
  • ternary relationships use 3 tables in DB, but can be modeled with parameterized properties in the object model
Zdeslav Vojkovic
  • 14,391
  • 32
  • 45