use of org.hibernate.persister.entity.EntityPersister in project hibernate-orm by hibernate.
the class EntityKey method deserialize.
/**
* Custom deserialization routine used during deserialization of a
* Session/PersistenceContext for increased performance.
*
* @param ois The stream from which to read the entry.
* @param sessionFactory The SessionFactory owning the Session being deserialized.
*
* @return The deserialized EntityEntry
*
* @throws IOException Thrown by Java I/O
* @throws ClassNotFoundException Thrown by Java I/O
*/
public static EntityKey deserialize(ObjectInputStream ois, SessionFactoryImplementor sessionFactory) throws IOException, ClassNotFoundException {
final Serializable id = (Serializable) ois.readObject();
final String entityName = (String) ois.readObject();
final EntityPersister entityPersister = sessionFactory.getEntityPersister(entityName);
return new EntityKey(id, entityPersister);
}
use of org.hibernate.persister.entity.EntityPersister in project hibernate-orm by hibernate.
the class DefaultLoadEventListener method loadFromSessionCache.
/**
* Attempts to locate the entity in the session-level cache.
* <p/>
* If allowed to return nulls, then if the entity happens to be found in
* the session cache, we check the entity type for proper handling
* of entity hierarchies.
* <p/>
* If checkDeleted was set to true, then if the entity is found in the
* session-level cache, it's current status within the session cache
* is checked to see if it has previously been scheduled for deletion.
*
* @param event The load event
* @param keyToLoad The EntityKey representing the entity to be loaded.
* @param options The load options.
*
* @return The entity from the session-level cache, or null.
*
* @throws HibernateException Generally indicates problems applying a lock-mode.
*/
protected Object loadFromSessionCache(final LoadEvent event, final EntityKey keyToLoad, final LoadEventListener.LoadType options) throws HibernateException {
SessionImplementor session = event.getSession();
Object old = session.getEntityUsingInterceptor(keyToLoad);
if (old != null) {
// this object was already loaded
EntityEntry oldEntry = session.getPersistenceContext().getEntry(old);
if (options.isCheckDeleted()) {
Status status = oldEntry.getStatus();
if (status == Status.DELETED || status == Status.GONE) {
return REMOVED_ENTITY_MARKER;
}
}
if (options.isAllowNulls()) {
final EntityPersister persister = event.getSession().getFactory().getEntityPersister(keyToLoad.getEntityName());
if (!persister.isInstance(old)) {
return INCONSISTENT_RTN_CLASS_MARKER;
}
}
upgradeLock(old, oldEntry, event.getLockOptions(), event.getSession());
}
return old;
}
use of org.hibernate.persister.entity.EntityPersister in project hibernate-orm by hibernate.
the class DefaultLoadEventListener method onLoad.
/**
* Handle the given load event.
*
* @param event The load event to be handled.
*
* @throws HibernateException
*/
public void onLoad(final LoadEvent event, final LoadEventListener.LoadType loadType) throws HibernateException {
final EntityPersister persister = getPersister(event);
if (persister == null) {
throw new HibernateException("Unable to locate persister: " + event.getEntityClassName());
}
final Class idClass = persister.getIdentifierType().getReturnedClass();
if (idClass != null && !idClass.isInstance(event.getEntityId())) {
checkIdClass(persister, event, loadType, idClass);
}
doOnLoad(persister, event, loadType);
}
use of org.hibernate.persister.entity.EntityPersister in project hibernate-orm by hibernate.
the class DefaultMergeEventListener method entityIsPersistent.
protected void entityIsPersistent(MergeEvent event, Map copyCache) {
LOG.trace("Ignoring persistent instance");
//TODO: check that entry.getIdentifier().equals(requestedId)
final Object entity = event.getEntity();
final EventSource source = event.getSession();
final EntityPersister persister = source.getEntityPersister(event.getEntityName(), entity);
//beforeQuery cascade!
((MergeContext) copyCache).put(entity, entity, true);
cascadeOnMerge(source, persister, entity, copyCache);
copyValues(persister, entity, entity, source, copyCache);
event.setResult(entity);
}
use of org.hibernate.persister.entity.EntityPersister in project hibernate-orm by hibernate.
the class DefaultSaveOrUpdateEventListener method entityIsDetached.
/**
* The given save-update event named a detached entity.
* <p/>
* Here, we will perform the update processing.
*
* @param event The update event to be handled.
*/
protected void entityIsDetached(SaveOrUpdateEvent event) {
LOG.trace("Updating detached instance");
if (event.getSession().getPersistenceContext().isEntryFor(event.getEntity())) {
//TODO: assertion only, could be optimized away
throw new AssertionFailure("entity was persistent");
}
Object entity = event.getEntity();
EntityPersister persister = event.getSession().getEntityPersister(event.getEntityName(), entity);
event.setRequestedId(getUpdateId(entity, persister, event.getRequestedId(), event.getSession()));
performUpdate(event, entity, persister);
}
Aggregations