Package org.hibernate.proxy

Examples of org.hibernate.proxy.HibernateProxy


                        // of subclasses, this will be root class, no the actual class. So it can't be used here.
                        String toEntityName;
            Serializable id;

                        if (newValue instanceof HibernateProxy) {
                          HibernateProxy hibernateProxy = (HibernateProxy) newValue;
                          toEntityName = session.bestGuessEntityName(newValue);
                          id = hibernateProxy.getHibernateLazyInitializer().getIdentifier();
              // We've got to initialize the object from the proxy to later read its state.  
              newValue = Tools.getTargetFromProxy(session.getFactory(), hibernateProxy);
                      } else {
                        toEntityName =  session.guessEntityName(newValue);

              IdMapper idMapper = verCfg.getEntCfg().get(toEntityName).getIdMapper();
                           id = (Serializable) idMapper.mapToIdFromEntity(newValue);
                      }

                        auditProcess.addWorkUnit(new CollectionChangeWorkUnit(session, toEntityName, verCfg, id, newValue));
                    }

                    if (oldValue != null) {
                      String toEntityName;
            Serializable id;

                      if(oldValue instanceof HibernateProxy) {
                          HibernateProxy hibernateProxy = (HibernateProxy) oldValue;
                          toEntityName = session.bestGuessEntityName(oldValue);
                          id = hibernateProxy.getHibernateLazyInitializer().getIdentifier();
              // We've got to initialize the object as we'll read it's state anyway.
              oldValue = Tools.getTargetFromProxy(session.getFactory(), hibernateProxy);
                      } else {
                        toEntityName =  session.guessEntityName(oldValue);
View Full Code Here


    if (obj == null) {
      return null;
    }

    if (obj instanceof HibernateProxy) {
      HibernateProxy hibernateProxy = (HibernateProxy) obj;
      return hibernateProxy.getHibernateLazyInitializer().getIdentifier();
    }

    return session.getEntityPersister(entityName, obj).getIdentifier(obj, session);
  }     
View Full Code Here

  }

  @Override
  public Object unproxy(Object instance) {
    if ( instance instanceof HibernateProxy ) {
      final HibernateProxy proxy = (HibernateProxy) instance;
      final LazyInitializer lazyInitializer = proxy.getHibernateLazyInitializer();
      Object initialized = lazyInitializer.getImplementation( hibernateSession );
      if ( initialized != null ) {
        return initialized;
      }
      else {
View Full Code Here

    private void replaceNonAuditIdProxies(Map versionsEntity, Number revision) {
        final Map originalId = (Map) versionsEntity.get( verCfg.getAuditEntCfg().getOriginalIdPropName() );
        for (Object key : originalId.keySet()) {
            Object value = originalId.get(key);
            if (value instanceof HibernateProxy) {
                HibernateProxy hibernateProxy = (HibernateProxy) value;
                LazyInitializer initializer = hibernateProxy.getHibernateLazyInitializer();
                final String entityName = initializer.getEntityName();
                final Serializable entityId = initializer.getIdentifier();
                if (verCfg.getEntCfg().isVersioned(entityName)) {
                    final String entityClassName = verCfg.getEntCfg().get(entityName).getEntityClassName();
                    Class entityClass;
View Full Code Here

    if ( value instanceof ElementWrapper ) {
      value = ( (ElementWrapper) value ).getElement();
    }
   
    if ( !Hibernate.isInitialized(value) ) {
      HibernateProxy proxy = (HibernateProxy) value;
      LazyInitializer li = proxy.getHibernateLazyInitializer();
      reassociateProxy(li, proxy);
      return true;
    }
    else {
      return false;
View Full Code Here

      value = ( (ElementWrapper) value ).getElement();
    }
   
    if ( value instanceof HibernateProxy ) {
      if ( log.isDebugEnabled() ) log.debug("setting proxy identifier: " + id);
      HibernateProxy proxy = (HibernateProxy) value;
      LazyInitializer li = proxy.getHibernateLazyInitializer();
      li.setIdentifier(id);
      reassociateProxy(li, proxy);
    }
  }
View Full Code Here

    if ( maybeProxy instanceof ElementWrapper ) {
      maybeProxy = ( (ElementWrapper) maybeProxy ).getElement();
    }
   
    if ( maybeProxy instanceof HibernateProxy ) {
      HibernateProxy proxy = (HibernateProxy) maybeProxy;
      LazyInitializer li = proxy.getHibernateLazyInitializer();
      if ( li.isUninitialized() ) {
        throw new PersistentObjectException(
            "object was an uninitialized proxy for " +
            li.getEntityName()
        );
View Full Code Here

    if ( maybeProxy instanceof ElementWrapper ) {
      maybeProxy = ( (ElementWrapper) maybeProxy ).getElement();
    }
   
    if ( maybeProxy instanceof HibernateProxy ) {
      HibernateProxy proxy = (HibernateProxy) maybeProxy;
      LazyInitializer li = proxy.getHibernateLazyInitializer();
      reassociateProxy(li, proxy);
      return li.getImplementation(); //initialize + unwrap the object
    }
    else {
      return maybeProxy;
View Full Code Here

    if ( mergeMap != null ) {
      Iterator mergeMapItr = mergeMap.entrySet().iterator();
      while ( mergeMapItr.hasNext() ) {
        final Map.Entry mergeMapEntry = ( Map.Entry ) mergeMapItr.next();
        if ( mergeMapEntry.getKey() instanceof HibernateProxy ) {
          final HibernateProxy proxy = ( HibernateProxy ) mergeMapEntry.getKey();
          if ( persister.isSubclassEntityName( proxy.getHibernateLazyInitializer().getEntityName() ) ) {
            boolean found = isFoundInParent(
                propertyName,
                childEntity,
                persister,
                collectionPersister,
                mergeMap.get( proxy )
            );
            if ( !found ) {
              found = isFoundInParent(
                  propertyName,
                  mergeMap.get( childEntity ),
                  persister,
                  collectionPersister,
                  mergeMap.get( proxy )
              );
            }
            if ( found ) {
              return proxy.getHibernateLazyInitializer().getIdentifier();
            }
          }
        }
      }
    }
View Full Code Here

    }
    if ( isReadOnly( object ) == readOnly ) {
      return;
    }
    if ( object instanceof HibernateProxy ) {
      HibernateProxy proxy = ( HibernateProxy ) object;
      setProxyReadOnly( proxy, readOnly );
      if ( Hibernate.isInitialized( proxy ) ) {
        setEntityReadOnly(
            proxy.getHibernateLazyInitializer().getImplementation(),
            readOnly
        );
      }
    }
    else {
View Full Code Here

TOP

Related Classes of org.hibernate.proxy.HibernateProxy

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.