|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.basedb.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.
Field Summary | |
---|---|
private int |
hashCode
Stores the hash code of the item. |
private int |
id
|
private int |
version
|
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. |
(package private) void |
setId(int id)
Set the id of the item. |
(package private) void |
setVersion(int version)
Set the version of the item. |
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 |
Field Detail |
---|
private int hashCode
hashCode()
private int id
private int version
Constructor Detail |
---|
public BasicData()
Method Detail |
---|
public String toString()
ClassName[id=55]
or
ClassName[new]
.
toString
in class Object
public 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 Object
public 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 Object
public int getId()
getId
in interface IdentifiableData
void setId(int id)
id
- The id of the itempublic int getVersion()
getVersion
in interface IdentifiableData
void setVersion(int version)
version
- The version of the item
|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |