protected final Serializable getId() { if ( id instanceof DelayedPostInsertIdentifier ) { return session.getPersistenceContext().getEntry( instance ).getId(); } return id; }
/** * Get the id value for an object that is actually associated with the session. This * is a bit stricter than getEntityIdentifierIfNotUnsaved(). */ public Serializable getEntityIdentifier(Object object) { if ( object instanceof HibernateProxy ) { return getProxyIdentifier(object); } else { EntityEntry entry = persistenceContext.getEntry(object); return entry != null ? entry.getId() : null; } }
protected final Serializable getKey() { finalKey = key; if ( key instanceof DelayedPostInsertIdentifier ) { // need to look it up from the persistence-context finalKey = session.getPersistenceContext().getEntry( collection.getOwner() ).getId(); if ( finalKey == key ) { // we may be screwed here since the collection action is about to execute // and we do not know the final owner key value } } return finalKey; }
/** * Get the id value for an object that is actually associated with the session. This * is a bit stricter than getEntityIdentifierIfNotUnsaved(). */ public Serializable getContextEntityIdentifier(Object object) { errorIfClosed(); if ( object instanceof HibernateProxy ) { return getProxyIdentifier(object); } else { EntityEntry entry = persistenceContext.getEntry(object); return entry != null ? entry.getId() : null; } }
public void forceFlush(EntityEntry e) throws HibernateException { if ( log.isDebugEnabled() ) { log.debug( "flushing to force deletion of re-saved object: " + MessageHelper.infoString( e.getPersister(), e.getId(), getFactory() ) ); } if ( persistenceContext.getCascadeLevel() > 0 ) { throw new ObjectDeletedException( "deleted object would be re-saved by cascade (remove deleted object from associations)", e.getId(), e.getPersister().getEntityName() ); } flush(); }
public void forceFlush(EntityEntry entityEntry) throws HibernateException { errorIfClosed(); if ( log.isDebugEnabled() ) { log.debug( "flushing to force deletion of re-saved object: " + MessageHelper.infoString( entityEntry.getPersister(), entityEntry.getId(), getFactory() ) ); } if ( persistenceContext.getCascadeLevel() > 0 ) { throw new ObjectDeletedException( "deleted object would be re-saved by cascade (remove deleted object from associations)", entityEntry.getId(), entityEntry.getPersister().getEntityName() ); } flush(); }
/** * Search the persistence context for an owner for the child object, * given a collection role */ public Serializable getOwnerId(String role, Object childObject) { int loc = role.lastIndexOf('.'); String entity = role.substring(0, loc); String property = role.substring( loc+1, role.length() ); EntityPersister persister = session.getFactory().getEntityPersister(entity); final CollectionPersister collectionPersister = session.getFactory().getCollectionPersister(role); CollectionType type = collectionPersister.getCollectionType(); Iterator entities = entityEntries.entrySet().iterator(); while ( entities.hasNext() ) { Map.Entry me = (Map.Entry) entities.next(); EntityEntry ee = (EntityEntry) me.getValue(); if ( persister.isSubclassEntityName( ee.getEntityName() ) ) { Object collection = persister.getPropertyValue( me.getKey(), property, session.getEntityMode() ); if ( collection!=null && type.contains(collection, childObject, collectionPersister, session) ) { return ee.getId(); } } } return null; }
private Serializable getId(Object entity, AbstractCollectionEvent event) { Serializable id = event.getAffectedOwnerIdOrNull(); if (id == null) { //most likely this recovery is unnecessary since Hibernate Core probably try that EntityEntry entityEntry = event.getSession().getPersistenceContext().getEntry(entity); id = entityEntry == null ? null : entityEntry.getId(); } return id; } }
private Serializable getId(Object entity, AbstractCollectionEvent event) { Serializable id = event.getAffectedOwnerIdOrNull(); if (id == null) { //most likely this recovery is unnecessary since Hibernate Core probably try that EntityEntry entityEntry = event.getSession().getPersistenceContext().getEntry(entity); id = entityEntry == null ? null : entityEntry.getId(); } return id; }
private Serializable getId(Object entity, AbstractCollectionEvent event) { Serializable id = event.getAffectedOwnerIdOrNull(); if (id == null) { //most likely this recovery is unnecessary since Hibernate Core probably try that EntityEntry entityEntry = event.getSession().getPersistenceContext().getEntry(entity); id = entityEntry == null ? null : entityEntry.getId(); } return id; }
public boolean isNullifiable(boolean earlyInsert, SessionImplementor session) { return getStatus() == Status.SAVING || ( earlyInsert ? !isExistsInDatabase() : session.getPersistenceContext().getNullifiableEntityKeys() .contains( new EntityKey( getId(), getPersister(), entityMode ) ) ); }
public boolean isNullifiable(boolean earlyInsert, SessionImplementor session) { return getStatus() == Status.SAVING || ( earlyInsert ? !isExistsInDatabase() : session.getPersistenceContext().getNullifiableEntityKeys() .contains( new EntityKey( getId(), getPersister(), entityMode ) ) ); }
/** * Return the existing proxy associated with the given <tt>EntityKey</tt>, or the * argument (the entity associated with the key) if no proxy exists. * (slower than the form above) */ public Object proxyFor(Object impl) throws HibernateException { EntityEntry e = getEntry(impl); EntityPersister p = e.getPersister(); return proxyFor( p, new EntityKey( e.getId(), p, session.getEntityMode() ), impl ); }
/** * Return the existing proxy associated with the given <tt>EntityKey</tt>, or the * argument (the entity associated with the key) if no proxy exists. * (slower than the form above) */ public Object proxyFor(Object impl) throws HibernateException { EntityEntry e = getEntry(impl); EntityPersister p = e.getPersister(); return proxyFor( p, new EntityKey( e.getId(), p, session.getEntityMode() ), impl ); }
private Object[] getValues( Object entity, EntityEntry entry, EntityMode entityMode, boolean mightBeDirty, SessionImplementor session ) { final Object[] loadedState = entry.getLoadedState(); final Status status = entry.getStatus(); final EntityPersister persister = entry.getPersister(); final Object[] values; if ( status == Status.DELETED ) { //grab its state saved at deletion values = entry.getDeletedState(); } else if ( !mightBeDirty && loadedState!=null ) { values = loadedState; } else { checkId( entity, persister, entry.getId(), entityMode ); // grab its current state values = persister.getPropertyValues( entity, entityMode ); checkNaturalId( persister, entry.getId(), values, loadedState, entityMode, session ); } return values; }
protected boolean invokeInterceptor( SessionImplementor session, Object entity, EntityEntry entry, final Object[] values, EntityPersister persister) { return session.getInterceptor().onFlushDirty( entity, entry.getId(), values, entry.getLoadedState(), persister.getPropertyNames(), persister.getPropertyTypes() ); }
public LockMode getCurrentLockMode(Object object) throws HibernateException { if ( object == null ) throw new NullPointerException( "null object passed to getCurrentLockMode()" ); if ( object instanceof HibernateProxy ) { object = ( (HibernateProxy) object ).getHibernateLazyInitializer().getImplementation(this); if ( object == null ) return LockMode.NONE; } EntityEntry e = persistenceContext.getEntry(object); if ( e == null ) throw new TransientObjectException( "Given object not associated with the session" ); if ( e.getStatus() != Status.MANAGED ) throw new ObjectDeletedException( "The given object was deleted", e.getId(), e.getPersister().getEntityName() ); return e.getLockMode(); }
public Serializable getIdentifier(Object object) throws HibernateException { if ( object instanceof HibernateProxy ) { LazyInitializer li = ( (HibernateProxy) object ).getHibernateLazyInitializer(); if ( li.getSession() != this ) { throw new TransientObjectException( "The proxy was not associated with this session" ); } return li.getIdentifier(); } else { EntityEntry entry = persistenceContext.getEntry(object); if ( entry == null ) { throw new TransientObjectException( "The instance was not associated with this session" ); } return entry.getId(); } }
public Serializable getIdentifier(Object object) throws HibernateException { errorIfClosed(); checkTransactionSynchStatus(); if ( object instanceof HibernateProxy ) { LazyInitializer li = ( (HibernateProxy) object ).getHibernateLazyInitializer(); if ( li.getSession() != this ) { throw new TransientObjectException( "The proxy was not associated with this session" ); } return li.getIdentifier(); } else { EntityEntry entry = persistenceContext.getEntry(object); if ( entry == null ) { throw new TransientObjectException( "The instance was not associated with this session" ); } return entry.getId(); } }
public LockMode getCurrentLockMode(Object object) throws HibernateException { errorIfClosed(); checkTransactionSynchStatus(); if ( object == null ) { throw new NullPointerException( "null object passed to getCurrentLockMode()" ); } if ( object instanceof HibernateProxy ) { object = ( (HibernateProxy) object ).getHibernateLazyInitializer().getImplementation(this); if ( object == null ) { return LockMode.NONE; } } EntityEntry e = persistenceContext.getEntry(object); if ( e == null ) { throw new TransientObjectException( "Given object not associated with the session" ); } if ( e.getStatus() != Status.MANAGED ) { throw new ObjectDeletedException( "The given object was deleted", e.getId(), e.getPersister().getEntityName() ); } return e.getLockMode(); }