Ray's playground

 

Mapping persistent classes(Chapter 3 of Hibernate In Action)

  Along with Java identity (memory location) and object equality, we pick up database identity (location in the persistent data store). We now have three methods
for identifying objects:
  ■ Object identity—Objects are identical if they occupy the same memory location in the JVM. This can be checked by using the == operator.
  ■ Object equality—Objects are equal if they have the same value, as defined by the equals(Object o) method. Classes that don’t explicitly override this method
inherit the implementation defined by java.lang.Object, which compares object identity.
  ■ Database identity—Objects stored in a relational database are identical if they represent the same row or, equivalently, share the same table and primary key
value.

  There are three different approaches to representing an inheritance hierarchy.

  These were catalogued by Scott Ambler [Ambler 2002] in his widely read paper “Mapping Objects to Relational Databases”:

  ■ Table per concrete class—Discard polymorphism and inheritance relationships completely from the relational model

  ■ Table per class hierarchy—Enable polymorphism by denormalizing the relational model and using a type discriminator column to hold type information

  ■ Table per subclass—Represent “is a” (inheritance) relationships as “has a” (foreign key) relationships 

posted on 2010-06-20 20:47  Ray Z  阅读(278)  评论(0编辑  收藏  举报

导航