@Override public Object proxyFor(EntityPersister persister, EntityKey key, Object impl) throws HibernateException { if ( !persister.hasProxy() ) { return impl; } final Object proxy = proxiesByKey.get( key ); return ( proxy != null ) ? narrowProxy( proxy, persister, key, impl ) : impl; }
private static boolean isSubsequentSelectDelayed(AssociationType type, SessionFactoryImplementor sessionFactory) { if ( type.isAnyType() ) { // we'd need more context here. this is only kept as part of the property state on the owning entity return false; } else if ( type.isEntityType() ) { return ( (EntityPersister) type.getAssociatedJoinable( sessionFactory ) ).hasProxy(); } else { final CollectionPersister cp = ( (CollectionPersister) type.getAssociatedJoinable( sessionFactory ) ); return cp.isLazy() || cp.isExtraLazy(); } }
/** * Create Hibernate proxy or retrieve the complete object of referenced, not audited entity. According to * {@link org.hibernate.envers.Audited#targetAuditMode()}} documentation, reference shall point to current * (non-historical) version of an entity. */ private Object createNotAuditedEntityReference( AuditReaderImplementor versionsReader, Class<?> entityClass, String entityName, Serializable primaryKey) { final EntityPersister entityPersister = versionsReader.getSessionImplementor().getFactory().getMetamodel() .entityPersister( entityName ); if ( entityPersister.hasProxy() ) { // If possible create a proxy. Returning complete object may affect performance. return versionsReader.getSession().load( entityClass, primaryKey ); } else { // If proxy is not allowed (e.g. @Proxy(lazy=false)) construct the original object. return versionsReader.getSession().get( entityClass, primaryKey ); } } }
/** * Creates Hibernate proxy or retrieves the complete object of an entity if proxy is not * allowed (e.g. @Proxy(lazy=false), final class). */ public static Object createProxyOrLoadImmediate( AuditReaderImplementor versionsReader, Class<?> entityClass, String entityName, Object entityId, Number revision, boolean removed, EnversService enversService) { final EntityPersister persister = versionsReader.getSessionImplementor() .getFactory() .getMetamodel() .entityPersister( entityName ); if ( persister.hasProxy() ) { return createProxy( versionsReader, entityClass, entityName, entityId, revision, removed, enversService ); } return loadImmediate( versionsReader, entityClass, entityName, entityId, revision, removed, enversService ); } }
/** * Does the mapping, and Hibernate default semantics, specify that * this association should be fetched by outer joining */ protected boolean isJoinedFetchEnabledInMapping(FetchMode config, AssociationType type) throws MappingException { if ( !type.isEntityType() && !type.isCollectionType() ) { return false; } else { if ( config == FetchMode.JOIN ) { return true; } if ( config == FetchMode.SELECT ) { return false; } if ( type.isEntityType() ) { //TODO: look at the owning property and check that it // isn't lazy (by instrumentation) EntityType entityType = (EntityType) type; EntityPersister persister = getFactory().getEntityPersister( entityType.getAssociatedEntityName() ); return !persister.hasProxy(); } else { return false; } } }
@Override public Object internalLoad( String entityName, Serializable id, boolean eager, boolean nullable) throws HibernateException { checkOpen(); EntityPersister persister = getFactory().getMetamodel().entityPersister( entityName ); // first, try to load it from the temp PC associated to this SS Object loaded = temporaryPersistenceContext.getEntity( generateEntityKey( id, persister ) ); if ( loaded != null ) { // we found it in the temp PC. Should indicate we are in the midst of processing a result set // containing eager fetches via join fetch return loaded; } if ( !eager && persister.hasProxy() ) { // if the metadata allowed proxy creation and caller did not request forceful eager loading, // generate a proxy return persister.createProxy( id, this ); } // otherwise immediately materialize it return get( entityName, id ); }
assertFalse( persister.isMutable() ); assertTrue( persister.buildCacheEntry( null, null, null, null ).isReferenceEntry() ); assertFalse( persister.hasProxy() );
assertFalse( persister.isMutable() ); assertTrue( persister.buildCacheEntry( null, null, null, null ).isReferenceEntry() ); assertFalse( persister.hasProxy() );
return FetchStyle.SELECT; else if ( !persister.hasProxy() ) { return FetchStyle.JOIN;
if ( !persister.hasProxy() ) { return load( event, persister, keyToLoad, options );
@Override public boolean hasProxy() { return persister.hasProxy(); }
/** * Return the existing proxy associated with the given <tt>EntityKey</tt>, or the * third argument (the entity associated with the key) if no proxy exists. Init * the proxy to the target implementation, if necessary. */ public Object proxyFor(EntityPersister persister, EntityKey key, Object impl) throws HibernateException { if ( !persister.hasProxy() ) return impl; Object proxy = proxiesByKey.get(key); if ( proxy != null ) { return narrowProxy(proxy, persister, key, impl); } else { return impl; } }
/** * Return the existing proxy associated with the given <tt>EntityKey</tt>, or the * third argument (the entity associated with the key) if no proxy exists. Init * the proxy to the target implementation, if necessary. */ public Object proxyFor(EntityPersister persister, EntityKey key, Object impl) throws HibernateException { if ( !persister.hasProxy() ) return impl; Object proxy = proxiesByKey.get(key); if ( proxy != null ) { return narrowProxy(proxy, persister, key, impl); } else { return impl; } }
/** * Return the existing proxy associated with the given <tt>EntityKey</tt>, or the * third argument (the entity associated with the key) if no proxy exists. Init * the proxy to the target implementation, if necessary. */ @Override public Object proxyFor(EntityPersister persister, EntityKey key, Object impl) throws HibernateException { if ( !persister.hasProxy() ) return impl; Object proxy = proxiesByKey.get(key); if ( proxy != null ) { return narrowProxy(proxy, persister, key, impl); } else { return impl; } }
/** * Return the existing proxy associated with the given <tt>EntityKey</tt>, or the * third argument (the entity associated with the key) if no proxy exists. Init * the proxy to the target implementation, if necessary. */ @Override public Object proxyFor(EntityPersister persister, EntityKey key, Object impl) throws HibernateException { if ( !persister.hasProxy() ) return impl; Object proxy = proxiesByKey.get(key); if ( proxy != null ) { return narrowProxy(proxy, persister, key, impl); } else { return impl; } }
public Object internalLoad( String entityName, Serializable id, boolean eager, boolean nullable) throws HibernateException { errorIfClosed(); EntityPersister persister = getFactory().getEntityPersister(entityName); if ( !eager && persister.hasProxy() ) { return persister.createProxy(id, this); } Object loaded = temporaryPersistenceContext.getEntity( new EntityKey(id, persister, EntityMode.POJO) ); //TODO: if not loaded, throw an exception return loaded==null ? get( entityName, id ) : loaded; }
/** * Does the mapping, and Hibernate default semantics, specify that * this association should be fetched by outer joining */ protected boolean isJoinedFetchEnabledInMapping(FetchMode config, AssociationType type) throws MappingException { if ( !type.isEntityType() && !type.isCollectionType() ) { return false; } else { if (config==FetchMode.JOIN) return true; if (config==FetchMode.SELECT) return false; if ( type.isEntityType() ) { //TODO: look at the owning property and check that it // isn't lazy (by instrumentation) EntityType entityType =(EntityType) type; EntityPersister persister = getFactory().getEntityPersister( entityType.getAssociatedEntityName() ); return !persister.hasProxy(); } else { return false; } } }
@Override public Object internalLoad( String entityName, Serializable id, boolean eager, boolean nullable) throws HibernateException { errorIfClosed(); EntityPersister persister = getFactory().getEntityPersister( entityName ); // first, try to load it from the temp PC associated to this SS Object loaded = temporaryPersistenceContext.getEntity( generateEntityKey( id, persister ) ); if ( loaded != null ) { // we found it in the temp PC. Should indicate we are in the midst of processing a result set // containing eager fetches via join fetch return loaded; } if ( !eager && persister.hasProxy() ) { // if the metadata allowed proxy creation and caller did not request forceful eager loading, // generate a proxy return persister.createProxy( id, this ); } // otherwise immediately materialize it return get( entityName, id ); }
@Override public Object internalLoad( String entityName, Serializable id, boolean eager, boolean nullable) throws HibernateException { errorIfClosed(); EntityPersister persister = getFactory().getEntityPersister( entityName ); // first, try to load it from the temp PC associated to this SS Object loaded = temporaryPersistenceContext.getEntity( generateEntityKey( id, persister ) ); if ( loaded != null ) { // we found it in the temp PC. Should indicate we are in the midst of processing a result set // containing eager fetches via join fetch return loaded; } if ( !eager && persister.hasProxy() ) { // if the metadata allowed proxy creation and caller did not request forceful eager loading, // generate a proxy return persister.createProxy( id, this ); } // otherwise immediately materialize it return get( entityName, id ); }
protected Object proxyOrLoad( final LoadEvent event, final EntityPersister persister, final EntityKey keyToLoad, final LoadEventListener.LoadType options) throws HibernateException { if (!persister.hasProxy()) { // this class has no proxies (so do a shortcut) return load(event, persister, keyToLoad, options); } final PersistenceContext persistenceContext = event.getSession().getPersistenceContext(); // using naked objects ghost objects rather than hibernate proxies - so should never be an // existing proxy Assert.assertNull(persistenceContext.getProxy(keyToLoad)); if (options.isAllowProxyCreation()) { return loadUnresolvedObject(event, persister, keyToLoad, options, persistenceContext); } else { // return a newly loaded object return load(event, persister, keyToLoad, options); } }