本文整理汇总了Java中org.hibernate.ObjectDeletedException类的典型用法代码示例。如果您正苦于以下问题:Java ObjectDeletedException类的具体用法?Java ObjectDeletedException怎么用?Java ObjectDeletedException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ObjectDeletedException类属于org.hibernate包,在下文中一共展示了ObjectDeletedException类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCurrentLockMode
import org.hibernate.ObjectDeletedException; //导入依赖的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();
}
示例2: forceFlush
import org.hibernate.ObjectDeletedException; //导入依赖的package包/类
@Override
public void forceFlush(EntityEntry entityEntry) throws HibernateException {
errorIfClosed();
if ( LOG.isDebugEnabled() ) {
LOG.debugf( "Flushing to force deletion of re-saved object: %s",
MessageHelper.infoString( entityEntry.getPersister(), entityEntry.getId(), getFactory() ) );
}
if ( persistenceContext.getCascadeLevel() > 0 ) {
throw new ObjectDeletedException(
"deleted object would be re-saved by cascade (remove deleted object from associations)",
entityEntry.getId(),
entityEntry.getPersister().getEntityName()
);
}
flush();
}
示例3: performSaveOrUpdate
import org.hibernate.ObjectDeletedException; //导入依赖的package包/类
protected Serializable performSaveOrUpdate(SaveOrUpdateEvent event) {
// this implementation is supposed to tolerate incorrect unsaved-value
// mappings, for the purpose of backward-compatibility
EntityEntry entry = event.getSession().getPersistenceContext().getEntry( event.getEntity() );
if ( entry!=null ) {
if ( entry.getStatus()== Status.DELETED ) {
throw new ObjectDeletedException( "deleted instance passed to update()", null, event.getEntityName() );
}
else {
return entityIsPersistent(event);
}
}
else {
entityIsDetached(event);
return null;
}
}
示例4: performSaveOrUpdate
import org.hibernate.ObjectDeletedException; //导入依赖的package包/类
protected Serializable performSaveOrUpdate(SaveOrUpdateEvent event) {
// this implementation is supposed to tolerate incorrect unsaved-value
// mappings, for the purpose of backward-compatibility
EntityEntry entry = event.getSession().getPersistenceContext().getEntry( event.getEntity() );
if ( entry!=null ) {
if ( entry.getStatus()==Status.DELETED ) {
throw new ObjectDeletedException( "deleted instance passed to update()", null, event.getEntityName() );
}
else {
return entityIsPersistent(event);
}
}
else {
entityIsDetached(event);
return null;
}
}
示例5: getCurrentLockMode
import org.hibernate.ObjectDeletedException; //导入依赖的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();
}
示例6: forceFlush
import org.hibernate.ObjectDeletedException; //导入依赖的package包/类
public void forceFlush(EntityEntry entityEntry) throws HibernateException {
errorIfClosed();
if ( log.isDebugEnabled() ) {
log.debug(
"flushing to force deletion of re-saved object: " +
MessageHelper.infoString( entityEntry.getPersister(), entityEntry.getId(), getFactory() )
);
}
if ( persistenceContext.getCascadeLevel() > 0 ) {
throw new ObjectDeletedException(
"deleted object would be re-saved by cascade (remove deleted object from associations)",
entityEntry.getId(),
entityEntry.getPersister().getEntityName()
);
}
flush();
}
示例7: removeItem
import org.hibernate.ObjectDeletedException; //导入依赖的package包/类
public void removeItem(Item item) {
try {
if (item == null) {
throw new IllegalArgumentException("item cannot be null");
}
if (item instanceof HomeCollectionItem) {
throw new IllegalArgumentException("cannot remove root item");
}
removeItemInternal(item);
getSession().flush();
} catch (ObjectNotFoundException onfe) {
throw new ItemNotFoundException("item not found");
} catch (ObjectDeletedException ode) {
throw new ItemNotFoundException("item not found");
} catch (UnresolvableObjectException uoe) {
throw new ItemNotFoundException("item not found");
} catch (HibernateException e) {
getSession().clear();
throw SessionFactoryUtils.convertHibernateAccessException(e);
}
}
示例8: upgradeLock
import org.hibernate.ObjectDeletedException; //导入依赖的package包/类
/**
* Performs a pessimistic lock upgrade on a given entity, if needed.
*
* @param object The entity for which to upgrade the lock.
* @param entry The entity's EntityEntry instance.
* @param lockOptions contains the requested lock mode.
* @param source The session which is the source of the event being processed.
*/
protected void upgradeLock(Object object, EntityEntry entry, LockOptions lockOptions, EventSource source) {
LockMode requestedLockMode = lockOptions.getLockMode();
if ( requestedLockMode.greaterThan( entry.getLockMode() ) ) {
// The user requested a "greater" (i.e. more restrictive) form of
// pessimistic lock
if ( entry.getStatus() != Status.MANAGED ) {
throw new ObjectDeletedException(
"attempted to lock a deleted instance",
entry.getId(),
entry.getPersister().getEntityName()
);
}
final EntityPersister persister = entry.getPersister();
if ( log.isTraceEnabled() ) {
log.tracev(
"Locking {0} in mode: {1}",
MessageHelper.infoString( persister, entry.getId(), source.getFactory() ),
requestedLockMode
);
}
final SoftLock lock;
final CacheKey ck;
if ( persister.hasCache() ) {
ck = source.generateCacheKey( entry.getId(), persister.getIdentifierType(), persister.getRootEntityName() );
lock = persister.getCacheAccessStrategy().lockItem( ck, entry.getVersion() );
}
else {
ck = null;
lock = null;
}
try {
if ( persister.isVersioned() && requestedLockMode == LockMode.FORCE ) {
// todo : should we check the current isolation mode explicitly?
Object nextVersion = persister.forceVersionIncrement(
entry.getId(), entry.getVersion(), source
);
entry.forceLocked( object, nextVersion );
}
else {
persister.lock( entry.getId(), entry.getVersion(), object, lockOptions, source );
}
entry.setLockMode(requestedLockMode);
}
finally {
// the database now holds a lock + the object is flushed from the cache,
// so release the soft lock
if ( persister.hasCache() ) {
persister.getCacheAccessStrategy().unlockItem( ck, lock );
}
}
}
}
示例9: onPersist
import org.hibernate.ObjectDeletedException; //导入依赖的package包/类
/**
* Handle the given create event.
*
* @param event The create event to be handled.
* @throws HibernateException
*/
public void onPersist(PersistEvent event, Map createCache) throws HibernateException {
final SessionImplementor source = event.getSession();
final Object object = event.getObject();
final Object entity;
if (object instanceof HibernateProxy) {
LazyInitializer li = ( (HibernateProxy) object ).getHibernateLazyInitializer();
if ( li.isUninitialized() ) {
if ( li.getSession()==source ) {
return; //NOTE EARLY EXIT!
}
else {
throw new PersistentObjectException("uninitialized proxy passed to persist()");
}
}
entity = li.getImplementation();
}
else {
entity = object;
}
int entityState = getEntityState(
entity,
event.getEntityName(),
source.getPersistenceContext().getEntry(entity),
source
);
switch (entityState) {
case DETACHED:
throw new PersistentObjectException(
"detached entity passed to persist: " +
getLoggableName( event.getEntityName(), entity )
);
case PERSISTENT:
entityIsPersistent(event, createCache);
break;
case TRANSIENT:
entityIsTransient(event, createCache);
break;
default:
throw new ObjectDeletedException(
"deleted entity passed to persist",
null,
getLoggableName( event.getEntityName(), entity )
);
}
}