Hibernate ORM LazyInitializer - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Hibernate ORM LazyInitializer class.

This code example shows how to use the following methods:getEntityName, getImplementation, getPersistentClass, isUninitialized, getClass
        if (o instanceof HibernateProxy) {
            HibernateProxy proxy = (HibernateProxy)o;
            LazyInitializer initializer = proxy.getHibernateLazyInitializer();
             
            String className = (
            	initializer.isUninitialized() ?
            	initializer.getEntityName() :
            	initializer.getImplementation().getClass().getName()
            );  
             
            if (className != null && className.length() > 0) {
                try { 
                    return TypeUtil.forName(className);
                } catch (Exception e) {
                    log.warn(e, "Could not get class with initializer: %s for: %s", initializer.getClass().getName(), className);
                } 
            } 
            // fallback... 
            return initializer.getPersistentClass();
        } 

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getEntityName, getImplementation, getPersistentClass, isUninitialized, getClass
        if (o instanceof HibernateProxy) {
            HibernateProxy proxy = (HibernateProxy)o;
            LazyInitializer initializer = proxy.getHibernateLazyInitializer();
             
            String className = (
            	initializer.isUninitialized() ?
            	initializer.getEntityName() :
            	initializer.getImplementation().getClass().getName()
            );  
             
            if (className != null && className.length() > 0) {
                try { 
                    return TypeUtil.forName(className);
                } catch (Exception e) {
                    log.warn(e, "Could not get class with initializer: %s for: %s", initializer.getClass().getName(), className);
                } 
            } 
            // fallback... 
            return initializer.getPersistentClass();
        } 

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getImplementation
This code example shows how to use the following methods:getImplementation
	@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 { 
				// This is the case in which the proxy was created by a different session. 
				// unproxyAndReassociate is the ultimate bomb, 
				// able to deal with a Session change: 
				return hibernateSession.getPersistenceContext().unproxyAndReassociate( proxy );
			} 
		} 
		return instance; 
	} 
 
	@Override 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getIdentifier, isUninitialized
        assert rev1.getReference() instanceof HibernateProxy;
 
        HibernateProxy proxyCreateByEnvers = (HibernateProxy) rev1.getReference();
        LazyInitializer lazyInitializer = proxyCreateByEnvers.getHibernateLazyInitializer();
 
        assert lazyInitializer.isUninitialized();
        assert lazyInitializer.getIdentifier() != null;
        assert lazyInitializer.getIdentifier().equals(tnae1.getId());
        assert lazyInitializer.isUninitialized();
 
        assert rev1.getReference().getId().equals(uste1.getId());
        assert rev1.getReference().getStr().equals(uste1.getStr());
        assert !lazyInitializer.isUninitialized();
    } 
} 
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getPersistentClass
 
    private Class getClazz(Object obj) {
        try { 
            HibernateProxy hibernateProxy = (HibernateProxy) obj;
            LazyInitializer lazyInitializer = hibernateProxy.getHibernateLazyInitializer();
            return lazyInitializer.getPersistentClass();
        } catch (ClassCastException e) {
            return obj.getClass(); 
        } 
    } 
 
    private String getOldValueToKey(Map map, String key) {
        String value = null;
        if (map.get(key) != null) {
            value = map.get(key).toString();
            if (!value.trim().equals("")) {
                return value;
            } else { 
                return ""; 
            } 
2
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getEntityName, isUninitialized
		} 
 
		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() 
				); 
			} 
			return li.getImplementation(); //unwrap the object 
		} 
		else { 
			return maybeProxy; 
		} 
	} 
 
	/** 
	 * Possibly unproxy the given reference and reassociate it with the current session. 
3
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
See Code Examples for Hibernate ORM LazyInitializer Methods: