org.hibernate.AssertionFailure Java Examples

The following examples show how to use org.hibernate.AssertionFailure. 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: EntityBinder.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public void bindTableForDiscriminatedSubclass(InFlightMetadataCollector.EntityTableXref superTableXref) {
	if ( !SingleTableSubclass.class.isInstance( persistentClass ) ) {
		throw new AssertionFailure(
				"Was expecting a discriminated subclass [" + SingleTableSubclass.class.getName() +
						"] but found [" + persistentClass.getClass().getName() + "] for entity [" +
						persistentClass.getEntityName() + "]"
		);
	}

	context.getMetadataCollector().addEntityTableXref(
			persistentClass.getEntityName(),
			context.getMetadataCollector().getDatabase().toIdentifier(
					context.getMetadataCollector().getLogicalTableName(
							superTableXref.getPrimaryTable()
					)
			),
			superTableXref.getPrimaryTable(),
			superTableXref
	);
}
 
Example #2
Source File: AbstractEntityEntry.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private EnumState(int offset, Class<E> enumType) {
	final E[] enumConstants = enumType.getEnumConstants();

	// In case any of the enums cannot be stored in 4 bits anymore, we'd have to re-structure the compressed
	// state int
	if ( enumConstants.length > 15 ) {
		throw new AssertionFailure( "Cannot store enum type " + enumType.getName() + " in compressed state as"
				+ " it has too many values." );
	}

	this.offset = offset;
	this.enumConstants = enumConstants;

	// a mask for reading the four bits, starting at the right offset
	this.mask = 0xF << offset;

	// a mask for setting the four bits at the right offset to 0
	this.unsetMask = 0xFFFF & ~mask;
}
 
Example #3
Source File: AttributeConverterManager.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public void addConverter(ConverterDescriptor descriptor) {
	if ( attributeConverterDescriptorsByClass == null ) {
		attributeConverterDescriptorsByClass = new ConcurrentHashMap<>();
	}

	final Object old = attributeConverterDescriptorsByClass.put(
			descriptor.getAttributeConverterClass(),
			descriptor
	);

	if ( old != null ) {
		throw new AssertionFailure(
				String.format(
						Locale.ENGLISH,
						"AttributeConverter class [%s] registered multiple times",
						descriptor.getAttributeConverterClass()
				)
		);
	}
}
 
Example #4
Source File: ActionQueue.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public void afterTransactionCompletion(boolean success) {
	while ( !processes.isEmpty() ) {
		try {
			processes.poll().doAfterTransactionCompletion( success, session );
		}
		catch (CacheException ce) {
			LOG.unableToReleaseCacheLock( ce );
			// continue loop
		}
		catch (Exception e) {
			throw new AssertionFailure( "Exception releasing cache locks", e );
		}
	}

	if ( session.getFactory().getSessionFactoryOptions().isQueryCacheEnabled() ) {
		session.getFactory().getCache().getTimestampsCache().invalidate(
				querySpacesToInvalidate.toArray( new String[querySpacesToInvalidate.size()] ),
				session
		);
	}
	querySpacesToInvalidate.clear();
}
 
Example #5
Source File: StatefulPersistenceContext.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Object[] extractNaturalIdValues(Object entity, EntityPersister persister) {
	if ( entity == null ) {
		throw new AssertionFailure( "Entity from which to extract natural id value(s) cannot be null" );
	}
	if ( persister == null ) {
		throw new AssertionFailure( "Persister to use in extracting natural id value(s) cannot be null" );
	}

	final int[] naturalIdentifierProperties = persister.getNaturalIdentifierProperties();
	final Object[] naturalIdValues = new Object[naturalIdentifierProperties.length];

	for ( int i = 0; i < naturalIdentifierProperties.length; i++ ) {
		naturalIdValues[i] = persister.getPropertyValue( entity, naturalIdentifierProperties[i] );
	}

	return naturalIdValues;
}
 
Example #6
Source File: FlushModeTypeHelper.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public static FlushModeType getFlushModeType(FlushMode flushMode) {
	if ( flushMode == FlushMode.ALWAYS ) {
		log.debug( "Interpreting Hibernate FlushMode#ALWAYS to JPA FlushModeType#AUTO; may cause problems if relying on FlushMode#ALWAYS-specific behavior" );
		return FlushModeType.AUTO;
	}
	else if ( flushMode == FlushMode.MANUAL ) {
		log.debug( "Interpreting Hibernate FlushMode#MANUAL to JPA FlushModeType#COMMIT; may cause problems if relying on FlushMode#MANUAL-specific behavior" );
		return FlushModeType.COMMIT;
	}
	else if ( flushMode == FlushMode.COMMIT ) {
		return FlushModeType.COMMIT;
	}
	else if ( flushMode == FlushMode.AUTO ) {
		return FlushModeType.AUTO;
	}

	throw new AssertionFailure( "unhandled FlushMode " + flushMode );
}
 
Example #7
Source File: SpecialOneToOneType.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Serializable disassemble(Object value, SharedSessionContractImplementor session, Object owner)
throws HibernateException {

	if (value==null) {
		return null;
	}
	else {
		// cache the actual id of the object, not the value of the
		// property-ref, which might not be initialized
		Object id = ForeignKeys.getEntityIdentifierIfNotUnsaved( getAssociatedEntityName(), value, session );
		if (id==null) {
			throw new AssertionFailure(
					"cannot cache a reference to an object with a null id: " + 
					getAssociatedEntityName() 
			);
		}
		return getIdentifierType(session).disassemble(id, session, owner);
	}
}
 
Example #8
Source File: BootstrapContextImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public void addAttributeConverterInfo(AttributeConverterInfo info) {
	if ( this.attributeConverterInfoMap == null ) {
		this.attributeConverterInfoMap = new HashMap<>();
	}

	final Object old = this.attributeConverterInfoMap.put( info.getConverterClass(), info );

	if ( old != null ) {
		throw new AssertionFailure(
				String.format(
						"AttributeConverter class [%s] registered multiple times",
						info.getConverterClass()
				)
		);
	}
}
 
Example #9
Source File: AbstractEntityPersister.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public void processInsertGeneratedProperties(
		Serializable id,
		Object entity,
		Object[] state,
		SharedSessionContractImplementor session) {
	if ( !hasInsertGeneratedProperties() ) {
		throw new AssertionFailure( "no insert-generated properties" );
	}
	processGeneratedProperties(
			id,
			entity,
			state,
			session,
			sqlInsertGeneratedValuesSelectString,
			GenerationTiming.INSERT
	);
}
 
Example #10
Source File: BasicProxyFactoryImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
public BasicProxyFactoryImpl(Class superClass, Class[] interfaces, ByteBuddyState byteBuddyState) {
	if ( superClass == null && ( interfaces == null || interfaces.length < 1 ) ) {
		throw new AssertionFailure( "attempting to build proxy without any superclass or interfaces" );
	}

	final Class<?> superClassOrMainInterface = superClass != null ? superClass : interfaces[0];
	final TypeCache.SimpleKey cacheKey = getCacheKey( superClass, interfaces );

	this.proxyClass = byteBuddyState.loadBasicProxy( superClassOrMainInterface, cacheKey, byteBuddy -> byteBuddy
			.with( new NamingStrategy.SuffixingRandom( PROXY_NAMING_SUFFIX, new NamingStrategy.SuffixingRandom.BaseNameResolver.ForFixedValue( superClassOrMainInterface.getName() ) ) )
			.subclass( superClass == null ? Object.class : superClass, ConstructorStrategy.Default.DEFAULT_CONSTRUCTOR )
			.implement( interfaces == null ? NO_INTERFACES : interfaces )
			.defineField( ProxyConfiguration.INTERCEPTOR_FIELD_NAME, ProxyConfiguration.Interceptor.class, Visibility.PRIVATE )
			.method( byteBuddyState.getProxyDefinitionHelpers().getVirtualNotFinalizerFilter() )
					.intercept( byteBuddyState.getProxyDefinitionHelpers().getDelegateToInterceptorDispatcherMethodDelegation() )
			.implement( ProxyConfiguration.class )
					.intercept( byteBuddyState.getProxyDefinitionHelpers().getInterceptorFieldAccessor() )
	);
	this.interceptor = new PassThroughInterceptor( proxyClass.getName() );
}
 
Example #11
Source File: BinderHelper.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public static MappedSuperclass getMappedSuperclassOrNull(
		XClass declaringClass,
		Map<XClass, InheritanceState> inheritanceStatePerClass,
		MetadataBuildingContext context) {
	boolean retrieve = false;
	if ( declaringClass != null ) {
		final InheritanceState inheritanceState = inheritanceStatePerClass.get( declaringClass );
		if ( inheritanceState == null ) {
			throw new org.hibernate.annotations.common.AssertionFailure(
					"Declaring class is not found in the inheritance state hierarchy: " + declaringClass
			);
		}
		if ( inheritanceState.isEmbeddableSuperclass() ) {
			retrieve = true;
		}
	}

	if ( retrieve ) {
		return context.getMetadataCollector().getMappedSuperclass(
				context.getBootstrapContext().getReflectionManager().toClass( declaringClass )
		);
	}
	else {
		return null;
	}
}
 
Example #12
Source File: ManyToOneType.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Serializable disassemble(
		Object value,
		SharedSessionContractImplementor session,
		Object owner) throws HibernateException {

	if ( value == null ) {
		return null;
	}
	else {
		// cache the actual id of the object, not the value of the
		// property-ref, which might not be initialized
		Object id = ForeignKeys.getEntityIdentifierIfNotUnsaved(
				getAssociatedEntityName(),
				value,
				session
		);
		if ( id == null ) {
			throw new AssertionFailure(
					"cannot cache a reference to an object with a null id: " + 
					getAssociatedEntityName()
			);
		}
		return getIdentifierType( session ).disassemble( id, session, owner );
	}
}
 
Example #13
Source File: DefaultFlushEntityEventListener.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * make sure user didn't mangle the id
 */
public void checkId(Object object, EntityPersister persister, Serializable id, SessionImplementor session)
		throws HibernateException {

	if ( id != null && id instanceof DelayedPostInsertIdentifier ) {
		// this is a situation where the entity id is assigned by a post-insert generator
		// and was saved outside the transaction forcing it to be delayed
		return;
	}

	if ( persister.canExtractIdOutOfEntity() ) {

		Serializable oid = persister.getIdentifier( object, session );
		if ( id == null ) {
			throw new AssertionFailure( "null id in " + persister.getEntityName() + " entry (don't flush the Session after an exception occurs)" );
		}
		if ( !persister.getIdentifierType().isEqual( id, oid, session.getFactory() ) ) {
			throw new HibernateException(
					"identifier of an instance of " + persister.getEntityName() + " was altered from "
							+ id + " to " + oid
			);
		}
	}

}
 
Example #14
Source File: DefaultSaveOrUpdateEventListener.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 );

}
 
Example #15
Source File: LockModeConverter.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Convert from the Hibernate specific LockMode to the JPA defined LockModeType.
 *
 * @param lockMode The Hibernate LockMode.
 *
 * @return The JPA LockModeType
 */
public static LockModeType convertToLockModeType(LockMode lockMode) {
	if ( lockMode == LockMode.NONE ) {
		return LockModeType.NONE;
	}
	else if ( lockMode == LockMode.OPTIMISTIC || lockMode == LockMode.READ ) {
		return LockModeType.OPTIMISTIC;
	}
	else if ( lockMode == LockMode.OPTIMISTIC_FORCE_INCREMENT || lockMode == LockMode.WRITE ) {
		return LockModeType.OPTIMISTIC_FORCE_INCREMENT;
	}
	else if ( lockMode == LockMode.PESSIMISTIC_READ ) {
		return LockModeType.PESSIMISTIC_READ;
	}
	else if ( lockMode == LockMode.PESSIMISTIC_WRITE
			|| lockMode == LockMode.UPGRADE
			|| lockMode == LockMode.UPGRADE_NOWAIT
			|| lockMode == LockMode.UPGRADE_SKIPLOCKED) {
		return LockModeType.PESSIMISTIC_WRITE;
	}
	else if ( lockMode == LockMode.PESSIMISTIC_FORCE_INCREMENT
			|| lockMode == LockMode.FORCE ) {
		return LockModeType.PESSIMISTIC_FORCE_INCREMENT;
	}
	throw new AssertionFailure( "unhandled lock mode " + lockMode );
}
 
Example #16
Source File: AbstractEntityPersister.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected String[] getSQLLazyUpdateByRowIdStrings() {
	if ( sqlLazyUpdateByRowIdString == null ) {
		throw new AssertionFailure( "no update by row id" );
	}
	String[] result = new String[getTableSpan()];
	result[0] = sqlLazyUpdateByRowIdString;
	System.arraycopy( sqlLazyUpdateStrings, 1, result, 1, getTableSpan() - 1 );
	return result;
}
 
Example #17
Source File: AbstractEntityPersister.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static int getTableId(String tableName, String[] tables) {
	for ( int j = 0; j < tables.length; j++ ) {
		if ( tableName.equalsIgnoreCase( tables[j] ) ) {
			return j;
		}
	}
	throw new AssertionFailure( "Table " + tableName + " not found" );
}
 
Example #18
Source File: AbstractCollectionPersister.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public EntityPersister getElementPersister() {
	if ( elementPersister == null ) {
		throw new AssertionFailure( "not an association" );
	}
	return elementPersister;
}
 
Example #19
Source File: JoinProcessor.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Translates an AST join type (i.e., the token type) into a JoinFragment.XXX join type.
 *
 * @param astJoinType The AST join type (from HqlSqlTokenTypes or SqlTokenTypes)
 * @return a JoinFragment.XXX join type.
 * @see JoinFragment
 * @see SqlTokenTypes
 */
public static int toHibernateJoinType(int astJoinType) {
	switch ( astJoinType ) {
		case LEFT_OUTER:
			return JoinFragment.LEFT_OUTER_JOIN;
		case INNER:
			return JoinFragment.INNER_JOIN;
		case RIGHT_OUTER:
			return JoinFragment.RIGHT_OUTER_JOIN;
		default:
			throw new AssertionFailure( "undefined join type " + astJoinType );
	}
}
 
Example #20
Source File: ConfigurationHelper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private static FlushMode getFlushMode(FlushModeType flushMode)  {
	switch(flushMode) {
		case AUTO:
			return FlushMode.AUTO;
		case COMMIT:
			return FlushMode.COMMIT;
		default:
			throw new AssertionFailure("Unknown FlushModeType: " + flushMode);
	}
}
 
Example #21
Source File: JoinProcessor.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Translates an AST join type (i.e., the token type) into a JoinFragment.XXX join type.
 *
 * @param astJoinType The AST join type (from HqlSqlTokenTypes or SqlTokenTypes)
 * @return a JoinFragment.XXX join type.
 * @see JoinFragment
 * @see SqlTokenTypes
 */
public static int toHibernateJoinType(int astJoinType) {
	switch ( astJoinType ) {
		case LEFT_OUTER:
			return JoinFragment.LEFT_OUTER_JOIN;
		case INNER:
			return JoinFragment.INNER_JOIN;
		case RIGHT_OUTER:
			return JoinFragment.RIGHT_OUTER_JOIN;
		default:
			throw new AssertionFailure( "undefined join type " + astJoinType );
	}
}
 
Example #22
Source File: StandardCacheEntryImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Assemble the previously disassembled state represented by this entry into the given entity instance.
 *
 * Additionally manages the PreLoadEvent callbacks.
 *
 * @param instance The entity instance
 * @param id The entity identifier
 * @param persister The entity persister
 * @param interceptor (currently unused)
 * @param session The session
 *
 * @return The assembled state
 *
 * @throws HibernateException Indicates a problem performing assembly or calling the PreLoadEventListeners.
 *
 * @see org.hibernate.type.Type#assemble
 * @see org.hibernate.type.Type#disassemble
 */
public Object[] assemble(
		final Object instance,
		final Serializable id,
		final EntityPersister persister,
		final Interceptor interceptor,
		final EventSource session) throws HibernateException {
	if ( !persister.getEntityName().equals( subclass ) ) {
		throw new AssertionFailure( "Tried to assemble a different subclass instance" );
	}

	//assembled state gets put in a new array (we read from cache by value!)
	final Object[] state = TypeHelper.assemble(
			disassembledState,
			persister.getPropertyTypes(),
			session, instance
	);

	//persister.setIdentifier(instance, id); //before calling interceptor, for consistency with normal load

	//TODO: reuse the PreLoadEvent
	final PreLoadEvent preLoadEvent = new PreLoadEvent( session )
			.setEntity( instance )
			.setState( state )
			.setId( id )
			.setPersister( persister );

	final EventListenerGroup<PreLoadEventListener> listenerGroup = session
			.getFactory()
			.getServiceRegistry()
			.getService( EventListenerRegistry.class )
			.getEventListenerGroup( EventType.PRE_LOAD );
	for ( PreLoadEventListener listener : listenerGroup.listeners() ) {
		listener.onPreLoad( preLoadEvent );
	}

	persister.setPropertyValues( instance, state );

	return state;
}
 
Example #23
Source File: ResultSetMappingBinder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Build a ResultSetMappingDefinition given a containing element for the "return-XXX" elements
 *
 * @param resultSetMappingSource The XML data as a JAXB binding
 * @param context The mapping state
 * @param prefix A prefix to apply to named ResultSet mapping; this is either {@code null} for
 * ResultSet mappings defined outside of any entity, or the name of the containing entity
 * if defined within the context of an entity
 *
 * @return The ResultSet mapping descriptor
 */
public static ResultSetMappingDefinition bind(
		ResultSetMappingBindingDefinition resultSetMappingSource,
		HbmLocalMetadataBuildingContext context,
		String prefix) {
	if ( StringHelper.isEmpty( prefix ) ) {
		throw new AssertionFailure( "Passed prefix was null; perhaps you meant to call the alternate #bind form?" );
	}

	final String resultSetName = prefix + '.' + resultSetMappingSource.getName();
	final ResultSetMappingDefinition binding = new ResultSetMappingDefinition( resultSetName );
	bind( resultSetMappingSource, binding, context );
	return binding;
}
 
Example #24
Source File: JoinProcessor.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Translates an AST join type (i.e., the token type) into a JoinFragment.XXX join type.
 *
 * @param astJoinType The AST join type (from HqlSqlTokenTypes or SqlTokenTypes)
 * @return a JoinFragment.XXX join type.
 * @see JoinFragment
 * @see SqlTokenTypes
 */
public static int toHibernateJoinType(int astJoinType) {
	switch ( astJoinType ) {
		case LEFT_OUTER:
			return JoinFragment.LEFT_OUTER_JOIN;
		case INNER:
			return JoinFragment.INNER_JOIN;
		case RIGHT_OUTER:
			return JoinFragment.RIGHT_OUTER_JOIN;
		default:
			throw new AssertionFailure( "undefined join type " + astJoinType );
	}
}
 
Example #25
Source File: ProxyFactoryFactoryImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public BasicProxyFactoryImpl(Class superClass, Class[] interfaces) {
	if ( superClass == null && ( interfaces == null || interfaces.length < 1 ) ) {
		throw new AssertionFailure( "attempting to build proxy without any superclass or interfaces" );
	}

	final javassist.util.proxy.ProxyFactory factory = new javassist.util.proxy.ProxyFactory();
	factory.setFilter( FINALIZE_FILTER );
	if ( superClass != null ) {
		factory.setSuperclass( superClass );
	}
	if ( interfaces != null && interfaces.length > 0 ) {
		factory.setInterfaces( interfaces );
	}
	proxyClass = factory.createClass();
}
 
Example #26
Source File: Ejb3Column.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public boolean isSecondary() {
	if ( propertyHolder == null ) {
		throw new AssertionFailure( "Should not call getTable() on column w/o persistent class defined" );
	}

	return StringHelper.isNotEmpty( explicitTableName )
			&& !propertyHolder.getTable().getName().equals( explicitTableName );
}
 
Example #27
Source File: MapBinder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void makeOneToManyMapKeyColumnNullableIfNotInProperty(
		final XProperty property) {
	final org.hibernate.mapping.Map map = (org.hibernate.mapping.Map) this.collection;
	if ( map.isOneToMany() &&
			property.isAnnotationPresent( MapKeyColumn.class ) ) {
		final Value indexValue = map.getIndex();
		if ( indexValue.getColumnSpan() != 1 ) {
			throw new AssertionFailure( "Map key mapped by @MapKeyColumn does not have 1 column" );
		}
		final Selectable selectable = indexValue.getColumnIterator().next();
		if ( selectable.isFormula() ) {
			throw new AssertionFailure( "Map key mapped by @MapKeyColumn is a Formula" );
		}
		Column column = (Column) map.getIndex().getColumnIterator().next();
		if ( !column.isNullable() ) {
			final PersistentClass persistentClass = ( ( OneToMany ) map.getElement() ).getAssociatedClass();
			// check if the index column has been mapped by the associated entity to a property;
			// @MapKeyColumn only maps a column to the primary table for the one-to-many, so we only
			// need to check "un-joined" properties.
			if ( !propertyIteratorContainsColumn( persistentClass.getUnjoinedPropertyIterator(), column ) ) {
				// The index column is not mapped to an associated entity property so we can
				// safely make the index column nullable.
				column.setNullable( true );
			}
		}
	}
}
 
Example #28
Source File: StatefulPersistenceContext.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setReadOnly(Object object, boolean readOnly) {
	if ( object == null ) {
		throw new AssertionFailure( "object must be non-null." );
	}
	if ( isReadOnly( object ) == readOnly ) {
		return;
	}
	if ( object instanceof HibernateProxy ) {
		final HibernateProxy proxy = (HibernateProxy) object;
		setProxyReadOnly( proxy, readOnly );
		if ( Hibernate.isInitialized( proxy ) ) {
			setEntityReadOnly(
					proxy.getHibernateLazyInitializer().getImplementation(),
					readOnly
			);
		}
	}
	else {
		setEntityReadOnly( object, readOnly );
		// PersistenceContext.proxyFor( entity ) returns entity if there is no proxy for that entity
		// so need to check the return value to be sure it is really a proxy
		final Object maybeProxy = getSession().getPersistenceContext().proxyFor( object );
		if ( maybeProxy instanceof HibernateProxy ) {
			setProxyReadOnly( (HibernateProxy) maybeProxy, readOnly );
		}
	}
}
 
Example #29
Source File: FlushModeTypeHelper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static FlushMode getFlushMode(FlushModeType flushModeType) {
	if ( flushModeType == FlushModeType.AUTO ) {
		return FlushMode.AUTO;
	}
	else if ( flushModeType == FlushModeType.COMMIT ) {
		return FlushMode.COMMIT;
	}

	throw new AssertionFailure( "unhandled FlushModeType " + flushModeType );
}
 
Example #30
Source File: InFlightMetadataCollectorImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void registerNaturalIdUniqueKeyBinder(String entityName, NaturalIdUniqueKeyBinder ukBinder) {
	if ( naturalIdUniqueKeyBinderMap == null ) {
		naturalIdUniqueKeyBinderMap = new HashMap<>();
	}
	final NaturalIdUniqueKeyBinder previous = naturalIdUniqueKeyBinderMap.put( entityName, ukBinder );
	if ( previous != null ) {
		throw new AssertionFailure( "Previous NaturalIdUniqueKeyBinder already registered for entity name : " + entityName );
	}
}