Skip to content

Commit

Permalink
HHH-8703 Remove need to support EntityKey de-serialization without ha…
Browse files Browse the repository at this point in the history
…ving access to a SessionFactory

(cherry picked from commit 9a3b141)

Conflicts:

	hibernate-core/src/main/java/org/hibernate/persister/entity/EntityPersister.java
  • Loading branch information
Sanne authored and sebersole committed Nov 18, 2013
1 parent cfefabc commit f96eabc
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 150 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -1658,7 +1658,7 @@ public static StatefulPersistenceContext deserialize(
LOG.trace( "Serializing persistent-context" );
}
final StatefulPersistenceContext rtn = new StatefulPersistenceContext( session );
SessionFactoryImplementor sfi = session==null ? null : session.getFactory();
SessionFactoryImplementor sfi = session.getFactory();

// during deserialization, we need to reconnect all proxies and
// collections to this session, as well as the EntityEntry and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,9 @@
import java.io.Serializable;

import org.hibernate.AssertionFailure;
import org.hibernate.engine.internal.EssentialEntityPersisterDetails;
import org.hibernate.internal.util.compare.EqualsHelper;
import org.hibernate.persister.entity.EntityEssentials;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.pretty.MessageHelper;
import org.hibernate.type.Type;

/**
* Uniquely identifies of an entity instance in a particular Session by identifier.
Expand All @@ -53,7 +50,7 @@ public final class EntityKey implements Serializable {

private final Serializable identifier;
private final int hashCode;
private final EntityEssentials persister;
private final EntityPersister persister;

/**
* Construct a unique identifier for an entity class instance.
Expand All @@ -80,11 +77,11 @@ public EntityKey(Serializable id, EntityPersister persister) {
* and so both equals and hashcode implementations can't be implemented correctly.
*
* @param identifier The identifier value
* @param fakePersister Is a placeholder for the EntityPersister, only providing essential methods needed for this purpose.
* @param persister The EntityPersister
* @param hashCode The hashCode needs to be provided as it can't be calculated correctly without the SessionFactory.
*/
private EntityKey(Serializable identifier, EntityEssentials fakePersister, int hashCode) {
this.persister = fakePersister;
private EntityKey(Serializable identifier, EntityPersister persister, int hashCode) {
this.persister = persister;
if ( identifier == null ) {
throw new AssertionFailure( "null identifier" );
}
Expand Down Expand Up @@ -158,12 +155,8 @@ public String toString() {
* @throws IOException Thrown by Java I/O
*/
public void serialize(ObjectOutputStream oos) throws IOException {
oos.writeObject( persister.getIdentifierType() );
oos.writeBoolean( isBatchLoadable() );
oos.writeObject( identifier );
oos.writeObject( persister.getEntityName() );
oos.writeObject( persister.getRootEntityName() );
oos.writeInt( hashCode );
}

/**
Expand All @@ -179,20 +172,9 @@ public void serialize(ObjectOutputStream oos) throws IOException {
* @throws ClassNotFoundException Thrown by Java I/O
*/
public static EntityKey deserialize(ObjectInputStream ois, SessionFactoryImplementor sessionFactory) throws IOException, ClassNotFoundException {
final Type identifierType = (Type) ois.readObject();
final boolean isBatchLoadable = ois.readBoolean();
final Serializable id = (Serializable) ois.readObject();
final String entityName = (String) ois.readObject();
final String rootEntityName = (String) ois.readObject();
final int hashCode = ois.readInt();
if ( sessionFactory != null) {
final EntityPersister entityPersister = sessionFactory.getEntityPersister( entityName );
return new EntityKey(id, entityPersister);
}
else {
//This version will produce an EntityKey which is technically unable to satisfy the equals contract!
final EntityEssentials fakePersister = new EssentialEntityPersisterDetails(identifierType, isBatchLoadable, entityName, rootEntityName);
return new EntityKey(id, fakePersister, hashCode);
}
final EntityPersister entityPersister = sessionFactory.getEntityPersister( entityName );
return new EntityKey(id, entityPersister);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
*
* @author Gavin King
*/
public interface EntityPersister extends OptimisticCacheSource, EntityEssentials {
public interface EntityPersister extends OptimisticCacheSource {

/**
* The property name of the "special" identifier property in HQL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.persister.entity.EntityEssentials;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.type.Type;

Expand Down Expand Up @@ -87,7 +86,7 @@ public static String infoString(String entityName, Serializable id) {
* @return An info string, in the form [FooBar#1]
*/
public static String infoString(
EntityEssentials persister,
EntityPersister persister,
Object id,
SessionFactoryImplementor factory) {
StringBuilder s = new StringBuilder();
Expand Down

0 comments on commit f96eabc

Please sign in to comment.