下面列出了怎么用org.hibernate.UnresolvableObjectException的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public final Object internalLoad(String entityName, Serializable id, boolean eager, boolean nullable)
throws HibernateException {
// todo : remove
LoadEventListener.LoadType type = nullable
? LoadEventListener.INTERNAL_LOAD_NULLABLE
: eager
? LoadEventListener.INTERNAL_LOAD_EAGER
: LoadEventListener.INTERNAL_LOAD_LAZY;
LoadEvent event = loadEvent;
loadEvent = null;
event = recycleEventInstance( event, id, entityName );
fireLoad( event, type );
Object result = event.getResult();
if ( !nullable ) {
UnresolvableObjectException.throwIfNull( result, id, entityName );
}
if ( loadEvent == null ) {
event.setEntityClassName( null );
event.setEntityId( null );
event.setInstanceToLoad( null );
event.setResult( null );
loadEvent = event;
}
return result;
}
public Object internalLoad(String entityName, Serializable id, boolean eager, boolean nullable) throws HibernateException {
// todo : remove
LoadEventListener.LoadType type = nullable ?
LoadEventListener.INTERNAL_LOAD_NULLABLE :
eager ? LoadEventListener.INTERNAL_LOAD_EAGER : LoadEventListener.INTERNAL_LOAD_LAZY;
LoadEvent event = new LoadEvent(id, entityName, true, this);
fireLoad(event, type);
if ( !nullable ) {
UnresolvableObjectException.throwIfNull( event.getResult(), id, entityName );
}
return event.getResult();
}
public HibernateObjectRetrievalFailureException(UnresolvableObjectException ex) {
super(ex.getEntityName(), ex.getIdentifier(), ex.getMessage(), ex);
}
public HibernateObjectRetrievalFailureException(UnresolvableObjectException ex) {
super(ex.getEntityName(), ex.getIdentifier(), ex.getMessage(), ex);
}
public HibernateObjectRetrievalFailureException(UnresolvableObjectException ex) {
super(ex.getEntityName(), ex.getIdentifier(), ex.getMessage(), ex);
}
public HibernateObjectRetrievalFailureException(UnresolvableObjectException ex) {
super(ex.getEntityName(), ex.getIdentifier(), ex.getMessage(), ex);
}
public HibernateObjectRetrievalFailureException(UnresolvableObjectException ex) {
super(ex.getEntityName(), ex.getIdentifier(), ex.getMessage(), ex);
}
@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.canWriteToCache() ) {
final EntityDataAccess cacheAccess = persister.getCacheAccessStrategy();
if ( cacheAccess != null ) {
final Object ck = cacheAccess.generateCacheKey(
id,
persister,
getFactory(),
getTenantIdentifier()
);
cacheAccess.evict( ck );
}
}
String previousFetchProfile = this.getLoadQueryInfluencers().getInternalFetchProfile();
Object result = null;
try {
this.getLoadQueryInfluencers().setInternalFetchProfile( "refresh" );
result = persister.load( id, entity, getNullSafeLockMode( lockMode ), this );
}
finally {
this.getLoadQueryInfluencers().setInternalFetchProfile( previousFetchProfile );
}
UnresolvableObjectException.throwIfNull( result, id, persister.getEntityName() );
}
public HibernateObjectRetrievalFailureException(UnresolvableObjectException ex) {
super(ex.getEntityName(), ex.getIdentifier(), ex.getMessage(), ex);
}
public HibernateObjectRetrievalFailureException(UnresolvableObjectException ex) {
super(ex.getEntityName(), ex.getIdentifier(), ex.getMessage(), ex);
}
public HibernateObjectRetrievalFailureException(UnresolvableObjectException ex) {
super(ex.getEntityName(), ex.getIdentifier(), ex.getMessage(), ex);
}
public List get(
QueryKey key,
Type[] returnTypes,
boolean isNaturalKeyLookup,
Set spaces,
SessionImplementor session) throws HibernateException {
if ( log.isDebugEnabled() ) {
log.debug("checking cached query results in region: " + regionName);
}
List cacheable = (List) queryCache.get(key);
if (cacheable==null) {
log.debug("query results were not found in cache");
return null;
}
Long timestamp = (Long) cacheable.get(0);
if ( !isNaturalKeyLookup && !isUpToDate(spaces, timestamp) ) {
log.debug("cached query results were not up to date");
return null;
}
log.debug("returning cached query results");
for ( int i=1; i<cacheable.size(); i++ ) {
if ( returnTypes.length==1 ) {
returnTypes[0].beforeAssemble( (Serializable) cacheable.get(i), session );
}
else {
TypeFactory.beforeAssemble( (Serializable[]) cacheable.get(i), returnTypes, session );
}
}
List result = new ArrayList( cacheable.size()-1 );
for ( int i=1; i<cacheable.size(); i++ ) {
try {
if ( returnTypes.length==1 ) {
result.add( returnTypes[0].assemble( (Serializable) cacheable.get(i), session, null ) );
}
else {
result.add( TypeFactory.assemble( (Serializable[]) cacheable.get(i), returnTypes, session, null ) );
}
}
catch (UnresolvableObjectException uoe) {
if (isNaturalKeyLookup) {
//TODO: not really completely correct, since
// the uoe could occur while resolving
// associations, leaving the PC in an
// inconsistent state
log.debug("could not reassemble cached result set");
queryCache.remove(key);
return null;
}
else {
throw uoe;
}
}
}
return result;
}
public void refresh(String entityName, Object entity, LockMode lockMode) {
final EntityPersister persister = this.getEntityPersister( entityName, entity );
final Serializable id = persister.getIdentifier( entity, getEntityMode() );
if ( log.isTraceEnabled() ) {
log.trace(
"refreshing transient " +
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 = new CacheKey(
id,
persister.getIdentifierType(),
persister.getRootEntityName(),
this.getEntityMode(),
this.getFactory()
);
persister.getCache().remove(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() );
}