当前位置: 首页>>代码示例>>Java>>正文


Java TransientObjectException类代码示例

本文整理汇总了Java中org.hibernate.TransientObjectException的典型用法代码示例。如果您正苦于以下问题:Java TransientObjectException类的具体用法?Java TransientObjectException怎么用?Java TransientObjectException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TransientObjectException类属于org.hibernate包,在下文中一共展示了TransientObjectException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getEntityIdentifierIfNotUnsaved

import org.hibernate.TransientObjectException; //导入依赖的package包/类
/**
 * Return the identifier of the persistent or transient object, or throw
 * an exception if the instance is "unsaved"
 * <p/>
 * Used by OneToOneType and ManyToOneType to determine what id value should
 * be used for an object that may or may not be associated with the session.
 * This does a "best guess" using any/all info available to use (not just the
 * EntityEntry).
 *
 * @param entityName The name of the entity
 * @param object The entity instance
 * @param session The session
 *
 * @return The identifier
 *
 * @throws TransientObjectException if the entity is transient (does not yet have an identifier)
 */
public static Serializable getEntityIdentifierIfNotUnsaved(
		final String entityName,
		final Object object,
		final SessionImplementor session) throws TransientObjectException {
	if ( object == null ) {
		return null;
	}
	else {
		Serializable id = session.getContextEntityIdentifier( object );
		if ( id == null ) {
			// context-entity-identifier returns null explicitly if the entity
			// is not associated with the persistence context; so make some
			// deeper checks...
			if ( isTransient( entityName, object, Boolean.FALSE, session ) ) {
				throw new TransientObjectException(
						"object references an unsaved transient instance - save the transient instance before flushing: " +
								(entityName == null ? session.guessEntityName( object ) : entityName)
				);
			}
			id = session.getEntityPersister( entityName, object ).getIdentifier( object, session );
		}
		return id;
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:42,代码来源:ForeignKeys.java

示例2: getCurrentLockMode

import org.hibernate.TransientObjectException; //导入依赖的package包/类
@Override
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();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:SessionImpl.java

示例3: getIdentifier

import org.hibernate.TransientObjectException; //导入依赖的package包/类
@Override
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();
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:SessionImpl.java

示例4: getEntityName

import org.hibernate.TransientObjectException; //导入依赖的package包/类
@Override
public String getEntityName(Object object) {
	errorIfClosed();
	checkTransactionSynchStatus();
	if (object instanceof HibernateProxy) {
		if ( !persistenceContext.containsProxy( object ) ) {
			throw new TransientObjectException("proxy was not associated with the session");
		}
		object = ( (HibernateProxy) object ).getHibernateLazyInitializer().getImplementation();
	}

	EntityEntry entry = persistenceContext.getEntry(object);
	if ( entry == null ) {
		throwTransientObjectException( object );
	}
	return entry.getPersister().getEntityName();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:SessionImpl.java

示例5: getUpdateId

import org.hibernate.TransientObjectException; //导入依赖的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

示例6: getEntityIdentifierIfNotUnsaved

import org.hibernate.TransientObjectException; //导入依赖的package包/类
/**
 * Return the identifier of the persistent or transient object, or throw
 * an exception if the instance is "unsaved"
 *
 * Used by OneToOneType and ManyToOneType to determine what id value should 
 * be used for an object that may or may not be associated with the session. 
 * This does a "best guess" using any/all info available to use (not just the 
 * EntityEntry).
 */
public static Serializable getEntityIdentifierIfNotUnsaved(
		final String entityName, 
		final Object object, 
		final SessionImplementor session) 
throws HibernateException {
	if ( object == null ) {
		return null;
	}
	else {
		Serializable id = session.getContextEntityIdentifier( object );
		if ( id == null ) {
			// context-entity-identifier returns null explicitly if the entity
			// is not associated with the persistence context; so make some
			// deeper checks...
			if ( isTransient(entityName, object, Boolean.FALSE, session) ) {
				throw new TransientObjectException(
						"object references an unsaved transient instance - save the transient instance before flushing: " +
						(entityName == null ? session.guessEntityName( object ) : entityName)
				);
			}
			id = session.getEntityPersister( entityName, object ).getIdentifier( object, session.getEntityMode() );
		}
		return id;
	}
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:35,代码来源:ForeignKeys.java

示例7: getUpdateId

import org.hibernate.TransientObjectException; //导入依赖的package包/类
/**
 * Determine the id to use for updating.
 *
 * @param entity The entity.
 * @param persister The entity persister
 * @param requestedId The requested identifier
 * @param entityMode The entity mode.
 *
 * @return The id.
 *
 * @throws TransientObjectException If the entity is considered transient.
 */
protected Serializable getUpdateId(
		Object entity,
		EntityPersister persister,
		Serializable requestedId,
		EntityMode entityMode) {
	// use the id assigned to the instance
	Serializable id = persister.getIdentifier( entity, entityMode );
	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:cacheonix,项目名称:cacheonix-core,代码行数:33,代码来源:DefaultSaveOrUpdateEventListener.java

示例8: getCurrentLockMode

import org.hibernate.TransientObjectException; //导入依赖的package包/类
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();
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:26,代码来源:SessionImpl.java

示例9: getIdentifier

import org.hibernate.TransientObjectException; //导入依赖的package包/类
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();
	}
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:19,代码来源:SessionImpl.java

示例10: getEntityName

import org.hibernate.TransientObjectException; //导入依赖的package包/类
public String getEntityName(Object object) {
	errorIfClosed();
	checkTransactionSynchStatus();
	if (object instanceof HibernateProxy) {
		if ( !persistenceContext.containsProxy( object ) ) {
			throw new TransientObjectException("proxy was not associated with the session");
		}
		object = ( (HibernateProxy) object ).getHibernateLazyInitializer().getImplementation();
	}

	EntityEntry entry = persistenceContext.getEntry(object);
	if ( entry == null ) {
		throwTransientObjectException( object );
	}
	return entry.getPersister().getEntityName();
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:17,代码来源:SessionImpl.java

示例11: testOneToOneGeneratedIds

import org.hibernate.TransientObjectException; //导入依赖的package包/类
public void testOneToOneGeneratedIds() {
	try {
		Session s = openSession();
		s.beginTransaction();
		Parent p = new Parent( "parent" );
		ParentInfo info = new ParentInfo( "xyz" );
		p.setInfo( info );
		info.setOwner( p );
		s.persist( p );
		try {
			s.getTransaction().commit();
			fail( "expecting TransientObjectException on flush" );
		}
		catch( TransientObjectException e ) {
			// expected result
			log.trace( "handled expected exception", e );
			s.getTransaction().rollback();
		}
		finally {
			s.close();
		}
	}
	finally {
		cleanupData();
	}
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:27,代码来源:CascadeTest.java

示例12: testOneToOneAssignedIds

import org.hibernate.TransientObjectException; //导入依赖的package包/类
public void testOneToOneAssignedIds() {
	try {
		Session s = openSession();
		s.beginTransaction();
		ParentAssigned p = new ParentAssigned( new Long( 1 ), "parent" );
		ParentInfoAssigned info = new ParentInfoAssigned( "something secret" );
		p.setInfo( info );
		info.setOwner( p );
		s.persist( p );
		try {
			s.getTransaction().commit();
			fail( "expecting TransientObjectException on flush" );
		}
		catch( TransientObjectException e ) {
			// expected result
			log.trace( "handled expected exception", e );
			s.getTransaction().rollback();
		}
		finally {
			s.close();
		}
	}
	finally {
		cleanupData();
	}
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:27,代码来源:CascadeTest.java

示例13: testManyToOnePropertyRefGeneratedIds

import org.hibernate.TransientObjectException; //导入依赖的package包/类
public void testManyToOnePropertyRefGeneratedIds() {
	try {
		Session s = openSession();
		s.beginTransaction();
		Parent p = new Parent( "parent" );
		Other other = new Other();
		other.setOwner( p );
		s.persist( other );
		try {
			s.getTransaction().commit();
			fail( "expecting TransientObjectException on flush" );
		}
		catch( TransientObjectException e ) {
			// expected result
			log.trace( "handled expected exception", e );
			s.getTransaction().rollback();
		}
		finally {
			s.close();
		}
	}
	finally {
		cleanupData();
	}
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:26,代码来源:CascadeTest.java

示例14: testManyToOnePropertyRefAssignedIds

import org.hibernate.TransientObjectException; //导入依赖的package包/类
public void testManyToOnePropertyRefAssignedIds() {
	try {
		Session s = openSession();
		s.beginTransaction();
		ParentAssigned p = new ParentAssigned( new Long( 1 ), "parent" );
		OtherAssigned other = new OtherAssigned( new Long( 2 ) );
		other.setOwner( p );
		s.persist( other );
		try {
			s.getTransaction().commit();
			fail( "expecting TransientObjectException on flush" );
		}
		catch( TransientObjectException e ) {
			// expected result
			log.trace( "handled expected exception", e );
			s.getTransaction().rollback();
		}
		finally {
			s.close();
		}
	}
	finally {
		cleanupData();
	}
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:26,代码来源:CascadeTest.java

示例15: testOneToOnePropertyRefGeneratedIds

import org.hibernate.TransientObjectException; //导入依赖的package包/类
public void testOneToOnePropertyRefGeneratedIds() {
	try {
		Session s = openSession();
		s.beginTransaction();
		Child c2 = new Child( "c2" );
		ChildInfo info = new ChildInfo( "blah blah blah" );
		c2.setInfo( info );
		info.setOwner( c2 );
		s.persist( c2 );
		try {
			s.getTransaction().commit();
			fail( "expecting TransientObjectException on flush" );
		}
		catch( TransientObjectException e ) {
			// expected result
			log.trace( "handled expected exception : " + e );
			s.getTransaction().rollback();
		}
		finally {
			s.close();
		}
	}
	finally {
		cleanupData();
	}
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:27,代码来源:CascadeTest.java


注:本文中的org.hibernate.TransientObjectException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。