FileDocCategorySizeDatePackage
EntityUniqueKey.javaAPI DocHibernate 3.2.54095Wed Feb 01 12:59:08 GMT 2006org.hibernate.engine

EntityUniqueKey

public class EntityUniqueKey extends Object implements Serializable
Used to uniquely key an entity instance in relation to a particular session by some unique property reference, as opposed to identifier.

Uniqueing information consists of the entity-name, the referenced property name, and the referenced property value.

see
EntityKey
author
Gavin King

Fields Summary
private final String
uniqueKeyName
private final String
entityName
private final Object
key
private final org.hibernate.type.Type
keyType
private final org.hibernate.EntityMode
entityMode
private final int
hashCode
Constructors Summary
public EntityUniqueKey(String entityName, String uniqueKeyName, Object semiResolvedKey, org.hibernate.type.Type keyType, org.hibernate.EntityMode entityMode, SessionFactoryImplementor factory)

		this.uniqueKeyName = uniqueKeyName;
		this.entityName = entityName;
		this.key = semiResolvedKey;
		this.keyType = keyType.getSemiResolvedType(factory);
		this.entityMode = entityMode;
		this.hashCode = generateHashCode(factory);
	
Methods Summary
private voidcheckAbilityToSerialize()

		// The unique property value represented here may or may not be
		// serializable, so we do an explicit check here in order to generate
		// a better error message
		if ( key != null && ! Serializable.class.isAssignableFrom( key.getClass() ) ) {
			throw new IllegalStateException(
					"Cannot serialize an EntityUniqueKey which represents a non " +
					"serializable property value [" + entityName + "." + uniqueKeyName + "]"
			);
		}
	
static org.hibernate.engine.EntityUniqueKeydeserialize(java.io.ObjectInputStream ois, SessionImplementor session)
Custom deserialization routine used during deserialization of a Session/PersistenceContext for increased performance.

param
ois The stream from which to read the entry.
param
session The session being deserialized.
return
The deserialized EntityEntry
throws
IOException
throws
ClassNotFoundException

		return new EntityUniqueKey(
				( String ) ois.readObject(),
		        ( String ) ois.readObject(),
		        ois.readObject(),
		        ( Type ) ois.readObject(),
		        ( EntityMode ) ois.readObject(),
		        session.getFactory()
		);
	
public booleanequals(java.lang.Object other)

		EntityUniqueKey that = (EntityUniqueKey) other;
		return that.entityName.equals(entityName) &&
		       that.uniqueKeyName.equals(uniqueKeyName) &&
		       keyType.isEqual(that.key, key, entityMode);
	
public intgenerateHashCode(SessionFactoryImplementor factory)

		int result = 17;
		result = 37 * result + entityName.hashCode();
		result = 37 * result + uniqueKeyName.hashCode();
		result = 37 * result + keyType.getHashCode(key, entityMode, factory);
		return result;
	
public java.lang.StringgetEntityName()

		return entityName;
	
public java.lang.ObjectgetKey()

		return key;
	
public java.lang.StringgetUniqueKeyName()

		return uniqueKeyName;
	
public inthashCode()

		return hashCode;
	
voidserialize(java.io.ObjectOutputStream oos)
Custom serialization routine used during serialization of a Session/PersistenceContext for increased performance.

param
oos The stream to which we should write the serial data.
throws
IOException

		checkAbilityToSerialize();
		oos.writeObject( uniqueKeyName );
		oos.writeObject( entityName );
		oos.writeObject( key );
		oos.writeObject( keyType );
		oos.writeObject( entityMode );
	
public java.lang.StringtoString()

		return "EntityUniqueKey" + MessageHelper.infoString(entityName, uniqueKeyName, key);
	
private voidwriteObject(java.io.ObjectOutputStream oos)

		checkAbilityToSerialize();
		oos.defaultWriteObject();