本文整理汇总了Java中org.hibernate.TransientObjectException类的典型用法代码示例。如果您正苦于以下问题:Java TransientObjectException类的具体用法?Java TransientObjectException怎么用?Java TransientObjectException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TransientObjectException类属于org.hibernate包,在下文中一共展示了TransientObjectException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: testOneToOnePropertyRefAssignedIds
import org.hibernate.TransientObjectException; //导入依赖的package包/类
public void testOneToOnePropertyRefAssignedIds() {
try {
Session s = openSession();
s.beginTransaction();
ChildAssigned c2 = new ChildAssigned( new Long( 3 ), "c3" );
ChildInfoAssigned info = new ChildInfoAssigned( new Long( 4 ), "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
示例17: exists
import org.hibernate.TransientObjectException; //导入依赖的package包/类
private boolean exists(Serializable key, Object indexOrElement, Type indexOrElementType, String sql, SessionImplementor session) {
try {
PreparedStatement st = session.getTransactionCoordinator()
.getJdbcCoordinator()
.getStatementPreparer()
.prepareStatement( sql );
try {
getKeyType().nullSafeSet( st, key, 1, session );
indexOrElementType.nullSafeSet( st, indexOrElement, keyColumnNames.length + 1, session );
ResultSet rs = session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( st );
try {
return rs.next();
}
finally {
session.getTransactionCoordinator().getJdbcCoordinator().release( rs, st );
}
}
catch ( TransientObjectException e ) {
return false;
}
finally {
session.getTransactionCoordinator().getJdbcCoordinator().release( st );
}
}
catch ( SQLException sqle ) {
throw getSQLExceptionHelper().convert(
sqle,
"could not check row existence: " +
MessageHelper.collectionInfoString( this, key, getFactory() ),
sqlSelectSizeString
);
}
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:34,代码来源:AbstractCollectionPersister.java
示例18: setEntityReadOnly
import org.hibernate.TransientObjectException; //导入依赖的package包/类
private void setEntityReadOnly(Object entity, boolean readOnly) {
final EntityEntry entry = getEntry( entity );
if ( entry == null ) {
throw new TransientObjectException( "Instance was not associated with this persistence context" );
}
entry.setReadOnly( readOnly, entity );
hasNonReadOnlyEntities = hasNonReadOnlyEntities || ! readOnly;
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:StatefulPersistenceContext.java
示例19: errorIfReadOnlySettingNotAvailable
import org.hibernate.TransientObjectException; //导入依赖的package包/类
private void errorIfReadOnlySettingNotAvailable() {
if ( session == null ) {
throw new TransientObjectException(
"Proxy is detached (i.e, session is null). The read-only/modifiable setting is only accessible when the proxy is associated with an open session."
);
}
if ( session.isClosed() ) {
throw new SessionException(
"Session is closed. The read-only/modifiable setting is only accessible when the proxy is associated with an open session."
);
}
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:13,代码来源:AbstractLazyInitializer.java
示例20: onLock
import org.hibernate.TransientObjectException; //导入依赖的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
注:本文中的org.hibernate.TransientObjectException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论