Java Code Examples for org.hibernate.persister.entity.EntityPersister#isMutable()
The following examples show how to use
org.hibernate.persister.entity.EntityPersister#isMutable() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractLazyInitializer.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public final void setReadOnly(boolean readOnly) { errorIfReadOnlySettingNotAvailable(); // only update if readOnly is different from current setting if ( this.readOnly != readOnly ) { final EntityPersister persister = session.getFactory().getEntityPersister( entityName ); if ( !persister.isMutable() && !readOnly ) { throw new IllegalStateException( "cannot make proxies [" + entityName + "#" + id + "] for immutable entities modifiable" ); } this.readOnly = readOnly; if ( initialized ) { EntityKey key = generateEntityKeyOrNull( getIdentifier(), session, getEntityName() ); if ( key != null && session.getPersistenceContext().containsEntity( key ) ) { session.getPersistenceContext().setReadOnly( target, readOnly ); } } } }
Example 2
Source File: SessionImpl.java From lams with GNU General Public License v2.0 | 5 votes |
private void verifyImmutableEntityUpdate(HQLQueryPlan plan) { if ( plan.isUpdate() ) { for ( EntityPersister entityPersister : getSessionFactory().getMetamodel().entityPersisters().values() ) { if ( !entityPersister.isMutable() ) { List<Serializable> entityQuerySpaces = new ArrayList<>( Arrays.asList( entityPersister.getQuerySpaces() ) ); entityQuerySpaces.retainAll( plan.getQuerySpaces() ); if ( !entityQuerySpaces.isEmpty() ) { ImmutableEntityUpdateQueryHandlingMode immutableEntityUpdateQueryHandlingMode = getSessionFactory() .getSessionFactoryOptions() .getImmutableEntityUpdateQueryHandlingMode(); String querySpaces = Arrays.toString( entityQuerySpaces.toArray() ); switch ( immutableEntityUpdateQueryHandlingMode ) { case WARNING: log.immutableEntityUpdateQuery(plan.getSourceQuery(), querySpaces); break; case EXCEPTION: throw new HibernateException( "The query: [" + plan.getSourceQuery() + "] attempts to update an immutable entity: " + querySpaces ); default: throw new UnsupportedOperationException( "The "+ immutableEntityUpdateQueryHandlingMode + " is not supported!" ); } } } } } }
Example 3
Source File: DefaultReactiveFlushEntityEventListener.java From hibernate-reactive with GNU Lesser General Public License v2.1 | 4 votes |
private boolean scheduleUpdate(final FlushEntityEvent event) { final EntityEntry entry = event.getEntityEntry(); final EventSource session = event.getSession(); final Object entity = event.getEntity(); final Status status = entry.getStatus(); final EntityPersister persister = entry.getPersister(); final Object[] values = event.getPropertyValues(); if ( LOG.isTraceEnabled() ) { if ( status == Status.DELETED ) { if ( !persister.isMutable() ) { LOG.tracev( "Updating immutable, deleted entity: {0}", MessageHelper.infoString( persister, entry.getId(), session.getFactory() ) ); } else if ( !entry.isModifiableEntity() ) { LOG.tracev( "Updating non-modifiable, deleted entity: {0}", MessageHelper.infoString( persister, entry.getId(), session.getFactory() ) ); } else { LOG.tracev( "Updating deleted entity: ", MessageHelper.infoString( persister, entry.getId(), session.getFactory() ) ); } } else { LOG.tracev( "Updating entity: {0}", MessageHelper.infoString( persister, entry.getId(), session.getFactory() ) ); } } final boolean intercepted = !entry.isBeingReplicated() && handleInterception( event ); // increment the version number (if necessary) final Object nextVersion = getNextVersion( event ); // if it was dirtied by a collection only int[] dirtyProperties = event.getDirtyProperties(); if ( event.isDirtyCheckPossible() && dirtyProperties == null ) { if ( !intercepted && !event.hasDirtyCollection() ) { throw new AssertionFailure( "dirty, but no dirty properties" ); } dirtyProperties = ArrayHelper.EMPTY_INT_ARRAY; } // check nullability but do not doAfterTransactionCompletion command execute // we'll use scheduled updates for that. new Nullability( session ).checkNullability( values, persister, true ); // schedule the update // note that we intentionally do _not_ pass in currentPersistentState! session.unwrap(ReactiveSession.class).getReactiveActionQueue().addAction( new ReactiveEntityUpdateAction( entry.getId(), values, dirtyProperties, event.hasDirtyCollection(), ( status == Status.DELETED && !entry.isModifiableEntity() ? persister.getPropertyValues( entity ) : entry.getLoadedState() ), entry.getVersion(), nextVersion, entity, entry.getRowId(), persister, session ) ); return intercepted; }
Example 4
Source File: DefaultFlushEntityEventListener.java From lams with GNU General Public License v2.0 | 4 votes |
private boolean scheduleUpdate(final FlushEntityEvent event) { final EntityEntry entry = event.getEntityEntry(); final EventSource session = event.getSession(); final Object entity = event.getEntity(); final Status status = entry.getStatus(); final EntityPersister persister = entry.getPersister(); final Object[] values = event.getPropertyValues(); if ( LOG.isTraceEnabled() ) { if ( status == Status.DELETED ) { if ( !persister.isMutable() ) { LOG.tracev( "Updating immutable, deleted entity: {0}", MessageHelper.infoString( persister, entry.getId(), session.getFactory() ) ); } else if ( !entry.isModifiableEntity() ) { LOG.tracev( "Updating non-modifiable, deleted entity: {0}", MessageHelper.infoString( persister, entry.getId(), session.getFactory() ) ); } else { LOG.tracev( "Updating deleted entity: ", MessageHelper.infoString( persister, entry.getId(), session.getFactory() ) ); } } else { LOG.tracev( "Updating entity: {0}", MessageHelper.infoString( persister, entry.getId(), session.getFactory() ) ); } } final boolean intercepted = !entry.isBeingReplicated() && handleInterception( event ); // increment the version number (if necessary) final Object nextVersion = getNextVersion( event ); // if it was dirtied by a collection only int[] dirtyProperties = event.getDirtyProperties(); if ( event.isDirtyCheckPossible() && dirtyProperties == null ) { if ( !intercepted && !event.hasDirtyCollection() ) { throw new AssertionFailure( "dirty, but no dirty properties" ); } dirtyProperties = ArrayHelper.EMPTY_INT_ARRAY; } // check nullability but do not doAfterTransactionCompletion command execute // we'll use scheduled updates for that. new Nullability( session ).checkNullability( values, persister, true ); // schedule the update // note that we intentionally do _not_ pass in currentPersistentState! session.getActionQueue().addAction( new EntityUpdateAction( entry.getId(), values, dirtyProperties, event.hasDirtyCollection(), ( status == Status.DELETED && !entry.isModifiableEntity() ? persister.getPropertyValues( entity ) : entry.getLoadedState() ), entry.getVersion(), nextVersion, entity, entry.getRowId(), persister, session ) ); return intercepted; }
Example 5
Source File: DefaultSaveOrUpdateEventListener.java From lams with GNU General Public License v2.0 | 4 votes |
protected void performUpdate( SaveOrUpdateEvent event, Object entity, EntityPersister persister) throws HibernateException { final boolean traceEnabled = LOG.isTraceEnabled(); if ( traceEnabled && !persister.isMutable() ) { LOG.trace( "Immutable instance passed to performUpdate()" ); } if ( traceEnabled ) { LOG.tracev( "Updating {0}", MessageHelper.infoString( persister, event.getRequestedId(), event.getSession().getFactory() ) ); } final EventSource source = event.getSession(); final EntityKey key = source.generateEntityKey( event.getRequestedId(), persister ); source.getPersistenceContext().checkUniqueness( key, entity ); if ( invokeUpdateLifecycle( entity, persister, source ) ) { reassociate( event, event.getObject(), event.getRequestedId(), persister ); return; } // this is a transient object with existing persistent state not loaded by the session new OnUpdateVisitor( source, event.getRequestedId(), entity ).process( entity, persister ); // TODO: put this stuff back in to read snapshot from // the second-level cache (needs some extra work) /*Object[] cachedState = null; if ( persister.hasCache() ) { CacheEntry entry = (CacheEntry) persister.getCache() .get( event.getRequestedId(), source.getTimestamp() ); cachedState = entry==null ? null : entry.getState(); //TODO: half-assemble this stuff }*/ source.getPersistenceContext().addEntity( entity, ( persister.isMutable() ? Status.MANAGED : Status.READ_ONLY ), null, // cachedState, key, persister.getVersion( entity ), LockMode.NONE, true, persister, false ); persister.afterReassociate( entity, source ); if ( traceEnabled ) { LOG.tracev( "Updating {0}", MessageHelper.infoString( persister, event.getRequestedId(), source.getFactory() ) ); } cascadeOnUpdate( event, persister, entity ); }
Example 6
Source File: DefaultSaveOrUpdateEventListener.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
protected void performUpdate( SaveOrUpdateEvent event, Object entity, EntityPersister persister) throws HibernateException { if ( !persister.isMutable() ) { log.trace( "immutable instance passed to doUpdate(), locking" ); reassociate( event, entity, event.getRequestedId(), persister ); } else { if ( log.isTraceEnabled() ) { log.trace( "updating " + MessageHelper.infoString( persister, event.getRequestedId(), event.getSession().getFactory() ) ); } final EventSource source = event.getSession(); EntityKey key = new EntityKey( event.getRequestedId(), persister, source.getEntityMode() ); source.getPersistenceContext().checkUniqueness( key, entity ); if ( invokeUpdateLifecycle( entity, persister, source ) ) { reassociate( event, event.getObject(), event.getRequestedId(), persister ); return; } // this is a transient object with existing persistent state not loaded by the session new OnUpdateVisitor( source, event.getRequestedId(), entity ).process( entity, persister ); //TODO: put this stuff back in to read snapshot from // the second-level cache (needs some extra work) /*Object[] cachedState = null; if ( persister.hasCache() ) { CacheEntry entry = (CacheEntry) persister.getCache() .get( event.getRequestedId(), source.getTimestamp() ); cachedState = entry==null ? null : entry.getState(); //TODO: half-assemble this stuff }*/ source.getPersistenceContext().addEntity( entity, Status.MANAGED, null, //cachedState, key, persister.getVersion( entity, source.getEntityMode() ), LockMode.NONE, true, persister, false, true //assume true, since we don't really know, and it doesn't matter ); persister.afterReassociate( entity, source ); if ( log.isTraceEnabled() ) { log.trace( "updating " + MessageHelper.infoString( persister, event.getRequestedId(), source.getFactory() ) ); } cascadeOnUpdate( event, persister, entity ); } }