org.riotfamily.riot.hibernate.domain
Class ActiveRecordSupport

java.lang.Object
  extended by org.riotfamily.common.beans.config.ConfigurableBean
      extended by org.riotfamily.riot.hibernate.domain.ActiveRecord
          extended by org.riotfamily.riot.hibernate.domain.ActiveRecordSupport
All Implemented Interfaces:
Serializable

public abstract class ActiveRecordSupport
extends ActiveRecord
implements Serializable

Abstract base class for ActiveRecords with a Long generated identifier. The class is Serializable and provides default implementations for both hashCode() and equals().

Since:
8.0
Author:
Felix Gnass [fgnass at neteye dot de]
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.riotfamily.riot.hibernate.domain.ActiveRecord
ActiveRecord.ForEachCallback<T>
 
Constructor Summary
ActiveRecordSupport()
           
 
Method Summary
 boolean equals(Object obj)
          Generic implementation that first checks for object identity.
 Long getId()
          Returns the identifier of this persistent instance.
 int hashCode()
          Default implementation that always returns 0.
 void setId(Long id)
          Sets the identifier of this persistent instance.
 String toString()
          Generic implementation that returns a String with the pattern <className>#<id> for persistent objects, or <className>@<identityHashCode> if the instance is unsaved.
 
Methods inherited from class org.riotfamily.riot.hibernate.domain.ActiveRecord
createQuery, delete, find, forEach, getSession, getSessionFactory, load, load, lock, merge, save, update
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ActiveRecordSupport

public ActiveRecordSupport()
Method Detail

getId

public Long getId()
Returns the identifier of this persistent instance.

Returns:
this instance's identifier

setId

public void setId(Long id)
Sets the identifier of this persistent instance.

Parameters:
id - an identifier

hashCode

public int hashCode()
Default implementation that always returns 0. This implementation is very inefficient for large collections as all instances will end up in the same hash bucket. Yet this is the only safe generic implementation, as it guarantees that the hashCode does not change while the object is contained in a collection.

If you plan to put your entities into large HashSets or HashMaps, you should consider to overwrite this method and implement it based on an immutable business key.

If your entities don't have such an immutable key you can use the id property instead, but keep in mind that collections won't be intact if you save a transient object after adding it to a set or map.

Overrides:
hashCode in class Object
See Also:
http://www.hibernate.org/109.html

equals

public boolean equals(Object obj)
Generic implementation that first checks for object identity. In case the objects are not the same instance, but this instance has a non-null id and the other object also extends ActiveRecordSupport, the method will compare both id values. If the ids are equal, the method calls Hibernate#getClass(Object)) for both objects and checks if the classes are the same.

Overrides:
equals in class Object

toString

public String toString()
Generic implementation that returns a String with the pattern <className>#<id> for persistent objects, or <className>@<identityHashCode> if the instance is unsaved.

Overrides:
toString in class Object