當前位置: 首頁>>代碼示例>>Java>>正文


Java EntityPersister.getIdentifier方法代碼示例

本文整理匯總了Java中org.hibernate.persister.entity.EntityPersister.getIdentifier方法的典型用法代碼示例。如果您正苦於以下問題:Java EntityPersister.getIdentifier方法的具體用法?Java EntityPersister.getIdentifier怎麽用?Java EntityPersister.getIdentifier使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.hibernate.persister.entity.EntityPersister的用法示例。


在下文中一共展示了EntityPersister.getIdentifier方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: update

import org.hibernate.persister.entity.EntityPersister; //導入方法依賴的package包/類
@Override
public void update(String entityName, Object entity) {
	errorIfClosed();
	EntityPersister persister = getEntityPersister(entityName, entity);
	Serializable id = persister.getIdentifier( entity, this );
	Object[] state = persister.getPropertyValues( entity );
	Object oldVersion;
	if ( persister.isVersioned() ) {
		oldVersion = persister.getVersion( entity );
		Object newVersion = Versioning.increment( oldVersion, persister.getVersionType(), this );
		Versioning.setVersion(state, newVersion, persister);
		persister.setPropertyValues( entity, state );
	}
	else {
		oldVersion = null;
	}
	persister.update(id, state, null, false, null, oldVersion, entity, null, this);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:19,代碼來源:StatelessSessionImpl.java

示例2: checkId

import org.hibernate.persister.entity.EntityPersister; //導入方法依賴的package包/類
/**
 * 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
			);
		}
	}

}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:28,代碼來源:DefaultFlushEntityEventListener.java

示例3: getUpdateId

import org.hibernate.persister.entity.EntityPersister; //導入方法依賴的package包/類
/**
 * Determine the id to use for updating.
 *
 * @param entity The entity.
 * @param persister The entity persister
 * @param requestedId The requested identifier
 * @param session The session
 *
 * @return The id.
 *
 * @throws TransientObjectException If the entity is considered transient.
 */
protected Serializable getUpdateId(
		Object entity,
		EntityPersister persister,
		Serializable requestedId,
		SessionImplementor session) {
	// use the id assigned to the instance
	Serializable id = persister.getIdentifier( entity, session );
	if ( id == null ) {
		// assume this is a newly instantiated transient object
		// which should be saved rather than updated
		throw new TransientObjectException(
				"The given object has a null identifier: " +
						persister.getEntityName()
		);
	}
	else {
		return id;
	}

}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:33,代碼來源:DefaultSaveOrUpdateEventListener.java

示例4: getIdOfOwnerOrNull

import org.hibernate.persister.entity.EntityPersister; //導入方法依賴的package包/類
/**
 * Get the id value from the owning entity key, usually the same as the key, but might be some
 * other property, in the case of property-ref
 *
 * @param key The collection owner key
 * @param session The session from which the request is originating.
 * @return The collection owner's id, if it can be obtained from the key;
 * otherwise, null is returned
 */
public Serializable getIdOfOwnerOrNull(Serializable key, SessionImplementor session) {
	Serializable ownerId = null;
	if ( foreignKeyPropertyName == null ) {
		ownerId = key;
	}
	else {
		Type keyType = getPersister( session ).getKeyType();
		EntityPersister ownerPersister = getPersister( session ).getOwnerEntityPersister();
		// TODO: Fix this so it will work for non-POJO entity mode
		Class ownerMappedClass = ownerPersister.getMappedClass();
		if ( ownerMappedClass.isAssignableFrom( keyType.getReturnedClass() ) &&
				keyType.getReturnedClass().isInstance( key ) ) {
			// the key is the owning entity itself, so get the ID from the key
			ownerId = ownerPersister.getIdentifier( key, session );
		}
		else {
			// TODO: check if key contains the owner ID
		}
	}
	return ownerId;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:31,代碼來源:CollectionType.java

示例5: entityIsTransient

import org.hibernate.persister.entity.EntityPersister; //導入方法依賴的package包/類
/**
 * Hibernate 3.1 implementation of ID transferral.
 */
@Override
protected void entityIsTransient(MergeEvent event, Map copyCache) {
	super.entityIsTransient(event, copyCache);
	SessionImplementor session = event.getSession();
	EntityPersister persister = session.getEntityPersister(event.getEntityName(), event.getEntity());
	// Extract id from merged copy (which is currently registered with Session).
	Serializable id = persister.getIdentifier(event.getResult(), session.getEntityMode());
	// Set id on original object (which remains detached).
	persister.setIdentifier(event.getOriginal(), id, session.getEntityMode());
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:14,代碼來源:IdTransferringMergeEventListener.java

示例6: delete

import org.hibernate.persister.entity.EntityPersister; //導入方法依賴的package包/類
@Override
public void delete(String entityName, Object entity) {
	errorIfClosed();
	EntityPersister persister = getEntityPersister(entityName, entity);
	Serializable id = persister.getIdentifier( entity, this );
	Object version = persister.getVersion( entity );
	persister.delete(id, version, entity, this);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:9,代碼來源:StatelessSessionImpl.java

示例7: refresh

import org.hibernate.persister.entity.EntityPersister; //導入方法依賴的package包/類
@Override
	public void refresh(String entityName, Object entity, LockMode lockMode) {
		final EntityPersister persister = this.getEntityPersister( entityName, entity );
		final Serializable id = persister.getIdentifier( entity, this );
		if ( LOG.isTraceEnabled() ) {
			LOG.tracev( "Refreshing transient {0}", MessageHelper.infoString( persister, id, this.getFactory() ) );
		}
		// TODO : can this ever happen???
//		EntityKey key = new EntityKey( id, persister, source.getEntityMode() );
//		if ( source.getPersistenceContext().getEntry( key ) != null ) {
//			throw new PersistentObjectException(
//					"attempted to refresh transient instance when persistent " +
//					"instance was already associated with the Session: " +
//					MessageHelper.infoString( persister, id, source.getFactory() )
//			);
//		}

		if ( persister.hasCache() ) {
			final CacheKey ck = generateCacheKey( id, persister.getIdentifierType(), persister.getRootEntityName() );
			persister.getCacheAccessStrategy().evict( ck );
		}

		String previousFetchProfile = this.getFetchProfile();
		Object result = null;
		try {
			this.setFetchProfile( "refresh" );
			result = persister.load( id, entity, lockMode, this );
		}
		finally {
			this.setFetchProfile( previousFetchProfile );
		}
		UnresolvableObjectException.throwIfNull( result, id, persister.getEntityName() );
	}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:34,代碼來源:StatelessSessionImpl.java

示例8: onLock

import org.hibernate.persister.entity.EntityPersister; //導入方法依賴的package包/類
/**
 * Handle the given lock event.
 *
 * @param event The lock event to be handled.
 * @throws HibernateException
 */
public void onLock(LockEvent event) throws HibernateException {

	if ( event.getObject() == null ) {
		throw new NullPointerException( "attempted to lock null" );
	}

	if ( event.getLockMode() == LockMode.WRITE ) {
		throw new HibernateException( "Invalid lock mode for lock()" );
	}

	if ( event.getLockMode() == LockMode.UPGRADE_SKIPLOCKED ) {
		LOG.explicitSkipLockedLockCombo();
	}

	SessionImplementor source = event.getSession();
	
	Object entity = source.getPersistenceContext().unproxyAndReassociate( event.getObject() );
	//TODO: if object was an uninitialized proxy, this is inefficient,
	//      resulting in two SQL selects
	
	EntityEntry entry = source.getPersistenceContext().getEntry(entity);
	if (entry==null) {
		final EntityPersister persister = source.getEntityPersister( event.getEntityName(), entity );
		final Serializable id = persister.getIdentifier( entity, source );
		if ( !ForeignKeys.isNotTransient( event.getEntityName(), entity, Boolean.FALSE, source ) ) {
			throw new TransientObjectException(
					"cannot lock an unsaved transient instance: " +
					persister.getEntityName()
			);
		}

		entry = reassociate(event, entity, id, persister);
		cascadeOnLock(event, persister, entity);
	}

	upgradeLock( entity, entry, event.getLockOptions(), event.getSession() );
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:44,代碼來源:DefaultLockEventListener.java

示例9: entityIsTransient

import org.hibernate.persister.entity.EntityPersister; //導入方法依賴的package包/類
protected void entityIsTransient(MergeEvent event, Map copyCache) {

		LOG.trace( "Merging transient instance" );

		final Object entity = event.getEntity();
		final EventSource source = event.getSession();

		final String entityName = event.getEntityName();
		final EntityPersister persister = source.getEntityPersister( entityName, entity );

		final Serializable id = persister.hasIdentifierProperty() ?
				persister.getIdentifier( entity, source ) :
				null;
		if ( copyCache.containsKey( entity ) ) {
			persister.setIdentifier( copyCache.get( entity ), id, source );
		}
		else {
			( (MergeContext) copyCache ).put( entity, source.instantiate( persister, id ), true ); //before cascade!
		}
		final Object copy = copyCache.get( entity );

		// cascade first, so that all unsaved objects get their
		// copy created before we actually copy
		//cascadeOnMerge(event, persister, entity, copyCache, Cascades.CASCADE_BEFORE_MERGE);
		super.cascadeBeforeSave( source, persister, entity, copyCache );
		copyValues( persister, entity, copy, source, copyCache, ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT );

		saveTransientEntity( copy, entityName, event.getRequestedId(), source, copyCache );

		// cascade first, so that all unsaved objects get their
		// copy created before we actually copy
		super.cascadeAfterSave( source, persister, entity, copyCache );
		copyValues( persister, entity, copy, source, copyCache, ForeignKeyDirection.FOREIGN_KEY_TO_PARENT );

		event.setResult( copy );
	}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:37,代碼來源:DefaultMergeEventListener.java

示例10: existsInDatabase

import org.hibernate.persister.entity.EntityPersister; //導入方法依賴的package包/類
private boolean existsInDatabase(Object entity, EventSource source, EntityPersister persister) {
	EntityEntry entry = source.getPersistenceContext().getEntry( entity );
	if ( entry == null ) {
		Serializable id = persister.getIdentifier( entity, source );
		if ( id != null ) {
			final EntityKey key = source.generateEntityKey( id, persister );
			final Object managedEntity = source.getPersistenceContext().getEntity( key );
			entry = source.getPersistenceContext().getEntry( managedEntity );
		}
	}

	return entry != null && entry.isExistsInDatabase();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:14,代碼來源:DefaultMergeEventListener.java

示例11: getCollectionOwner

import org.hibernate.persister.entity.EntityPersister; //導入方法依賴的package包/類
@Override
public Object getCollectionOwner(Serializable key, CollectionPersister collectionPersister) throws MappingException {
	// todo : we really just need to add a split in the notions of:
	//		1) collection key
	//		2) collection owner key
	// these 2 are not always the same.  Same is true in the case of ToOne associations with property-ref...
	final EntityPersister ownerPersister = collectionPersister.getOwnerEntityPersister();
	if ( ownerPersister.getIdentifierType().getReturnedClass().isInstance( key ) ) {
		return getEntity( session.generateEntityKey( key, collectionPersister.getOwnerEntityPersister() ) );
	}

	// we have a property-ref type mapping for the collection key.  But that could show up a few ways here...
	//
	//		1) The incoming key could be the entity itself...
	if ( ownerPersister.isInstance( key ) ) {
		final Serializable owenerId = ownerPersister.getIdentifier( key, session );
		if ( owenerId == null ) {
			return null;
		}
		return getEntity( session.generateEntityKey( owenerId, ownerPersister ) );
	}

	final CollectionType collectionType = collectionPersister.getCollectionType();

	//		2) The incoming key is most likely the collection key which we need to resolve to the owner key
	//			find the corresponding owner instance
	//			a) try by EntityUniqueKey
	if ( collectionType.getLHSPropertyName() != null ) {
		final Object owner = getEntity(
				new EntityUniqueKey(
						ownerPersister.getEntityName(),
						collectionType.getLHSPropertyName(),
						key,
						collectionPersister.getKeyType(),
						ownerPersister.getEntityMode(),
						session.getFactory()
				)
		);
		if ( owner != null ) {
			return owner;
		}

		//		b) try by EntityKey, which means we need to resolve owner-key -> collection-key
		//			IMPL NOTE : yes if we get here this impl is very non-performant, but PersistenceContext
		//					was never designed to handle this case; adding that capability for real means splitting
		//					the notions of:
		//						1) collection key
		//						2) collection owner key
		// 					these 2 are not always the same (same is true in the case of ToOne associations with
		// 					property-ref).  That would require changes to (at least) CollectionEntry and quite
		//					probably changes to how the sql for collection initializers are generated
		//
		//			We could also possibly see if the referenced property is a natural id since we already have caching
		//			in place of natural id snapshots.  BUt really its better to just do it the right way ^^ if we start
		// 			going that route
		final Serializable ownerId = ownerPersister.getIdByUniqueKey( key, collectionType.getLHSPropertyName(), session );
		return getEntity( session.generateEntityKey( ownerId, ownerPersister ) );
	}

	// as a last resort this is what the old code did...
	return getEntity( session.generateEntityKey( key, collectionPersister.getOwnerEntityPersister() ) );
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:63,代碼來源:StatefulPersistenceContext.java

示例12: entityIsDetached

import org.hibernate.persister.entity.EntityPersister; //導入方法依賴的package包/類
protected void entityIsDetached(MergeEvent event, Map copyCache) {

		LOG.trace( "Merging detached instance" );

		final Object entity = event.getEntity();
		final EventSource source = event.getSession();

		final EntityPersister persister = source.getEntityPersister( event.getEntityName(), entity );
		final String entityName = persister.getEntityName();

		Serializable id = event.getRequestedId();
		if ( id == null ) {
			id = persister.getIdentifier( entity, source );
		}
		else {
			// check that entity id = requestedId
			Serializable entityId = persister.getIdentifier( entity, source );
			if ( !persister.getIdentifierType().isEqual( id, entityId, source.getFactory() ) ) {
				throw new HibernateException( "merge requested with id not matching id of passed entity" );
			}
		}

		String previousFetchProfile = source.getFetchProfile();
		source.setFetchProfile( "merge" );
		//we must clone embedded composite identifiers, or
		//we will get back the same instance that we pass in
		final Serializable clonedIdentifier = (Serializable) persister.getIdentifierType()
				.deepCopy( id, source.getFactory() );
		final Object result = source.get( entityName, clonedIdentifier );
		source.setFetchProfile( previousFetchProfile );

		if ( result == null ) {
			//TODO: we should throw an exception if we really *know* for sure
			//      that this is a detached instance, rather than just assuming
			//throw new StaleObjectStateException(entityName, id);

			// we got here because we assumed that an instance
			// with an assigned id was detached, when it was
			// really persistent
			entityIsTransient( event, copyCache );
		}
		else {
			( (MergeContext) copyCache ).put( entity, result, true ); //before cascade!

			final Object target = source.getPersistenceContext().unproxy( result );
			if ( target == entity ) {
				throw new AssertionFailure( "entity was not detached" );
			}
			else if ( !source.getEntityName( target ).equals( entityName ) ) {
				throw new WrongClassException(
						"class of the given object did not match class of persistent copy",
						event.getRequestedId(),
						entityName
				);
			}
			else if ( isVersionChanged( entity, source, persister, target ) ) {
				if ( source.getFactory().getStatistics().isStatisticsEnabled() ) {
					source.getFactory().getStatisticsImplementor()
							.optimisticFailure( entityName );
				}
				throw new StaleObjectStateException( entityName, id );
			}

			// cascade first, so that all unsaved objects get their
			// copy created before we actually copy
			cascadeOnMerge( source, persister, entity, copyCache );
			copyValues( persister, entity, target, source, copyCache );

			//copyValues works by reflection, so explicitly mark the entity instance dirty
			markInterceptorDirty( entity, target, persister );

			event.setResult( result );
		}

	}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:76,代碼來源:DefaultMergeEventListener.java


注:本文中的org.hibernate.persister.entity.EntityPersister.getIdentifier方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。