|
Last update: 2011-06-23 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.proteios.core.data.BasicData
public abstract class BasicData
This is the root superclass of all data classes. Each class must inherit from
this class or one of the subclasses. The main purpose of this class is to handle
object identity. It contains a Hibernate mapping for the getId() property
and overrides the default implementations of the equals(Object) and hashCode() methods.
For all practical purposes object identity is the same as database identity, ie.
two objects are considered equal if they reference the same row in the database.
Objects that has not yet been saved to the database should be handled carefully
and not be put into Set:s or Map:s since that may break
the contract for the equals() and hashCode() methods.
We recommend that the equals() and hashCode() methods
not are overridden in subclasses, unless you really know what you are doing.
Actually, we would have liked to make the methods final but that
would disable the proxy feature of Hibernate.
| Constructor Summary | |
|---|---|
BasicData()
|
|
| Method Summary | |
|---|---|
boolean |
equals(Object other)
Check if this item is equal to another item. |
int |
getId()
Get the id of the item. |
int |
getVersion()
Get the version of the item. |
int |
hashCode()
For new items (getId() returns 0) the hash code is the same as returned by the System.identityHashCode() method. |
String |
toString()
The string will look like ClassName[id=55] or
ClassName[new]. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public BasicData()
| Method Detail |
|---|
public String toString()
ClassName[id=55] or
ClassName[new].
toString in class Objectpublic boolean equals(Object other)
other object can be a Hibernate proxy, which is
a dynamically generated subclass of the actual class.
Do not override this method in a subclass!
equals in class Objectpublic int hashCode()
System.identityHashCode() method.
Items loaded from the database uses the id as the hash code. We must also
consider the case were a new object is saved to the database. Our recommendation
is to not place the object in Set (or other structure) that
calls the hashCode method before the object is saved to the
database. If you do that the contract for the equals()/hashCode()
method is broken and equals() may return true even if hashCode()
returns different values.
Do not override this method in a subclass!
hashCode in class Objectpublic int getId()
getId in interface IdentifiableDatapublic int getVersion()
getVersion in interface IdentifiableData
|
Last update: 2011-06-23 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||