Web site template - 162 4.2.1 CHAPTER 4 Mapping persistent classes Understanding

162 4.2.1 CHAPTER 4 Mapping persistent classes Understanding Java identity and equality Java developers understand the difference between Java object identity and equality. Object identity, ==, is a notion defined by the Java virtual machine. Two object references are identical if they point to the same memory location. On the other hand, object equality is a notion defined by classes that implement the equals() method, sometimes also referred to as equivalence. Equivalence means that two different (nonidentical) objects have the same value. Two different instances of String are equal if they represent the same sequence of characters, even though they each have their own location in the memory space of the virtual machine. (If you re a Java guru, we acknowledge that String is a special case. Assume we used a different class to make the same point.) Persistence complicates this picture. With object/relational persistence, a persistent object is an in-memory representation of a particular row of a database table. Along with Java identity (memory location) and object equality, you pick up database identity (which is the location in the persistent data store). You now have three methods for identifying objects: Objects are identical if they occupy the same memory location in the JVM. This can be checked by using the == operator. This concept is known as object identity. 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. This concept is known as equality. Objects stored in a relational database are identical if they represent the same row or, equivalently, if they share the same table and primary key value. This concept is known as database identity. We now need to look at how database identity relates to object identity in Hibernate, and how database identity is expressed in the mapping metadata. Handling database identity Hibernate exposes database identity to the application in two ways: The value of the identifier property of a persistent instance The value returned by Session.getIdentifier(Object entity)
We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.