Search in sources :

Example 66 with HibernateProxy

use of org.hibernate.proxy.HibernateProxy in project BroadleafCommerce by BroadleafCommerce.

the class BundleOrderItemImpl method getSku.

@Override
public Sku getSku() {
    if (deproxiedSku == null) {
        PostLoaderDao postLoaderDao = DefaultPostLoaderDao.getPostLoaderDao();
        if (postLoaderDao != null && sku.getId() != null) {
            Long id = sku.getId();
            deproxiedSku = postLoaderDao.find(SkuImpl.class, id);
        } else if (sku instanceof HibernateProxy) {
            deproxiedSku = HibernateUtils.deproxy(sku);
        } else {
            deproxiedSku = sku;
        }
    }
    return deproxiedSku;
}
Also used : SkuImpl(org.broadleafcommerce.core.catalog.domain.SkuImpl) DefaultPostLoaderDao(org.broadleafcommerce.common.persistence.DefaultPostLoaderDao) PostLoaderDao(org.broadleafcommerce.common.persistence.PostLoaderDao) HibernateProxy(org.hibernate.proxy.HibernateProxy)

Example 67 with HibernateProxy

use of org.hibernate.proxy.HibernateProxy in project BroadleafCommerce by BroadleafCommerce.

the class BundleOrderItemImpl method getProductBundle.

@Override
public ProductBundle getProductBundle() {
    if (deproxiedProductBundle == null) {
        PostLoaderDao postLoaderDao = DefaultPostLoaderDao.getPostLoaderDao();
        if (postLoaderDao != null && productBundle.getId() != null) {
            Long id = productBundle.getId();
            deproxiedProductBundle = postLoaderDao.find(ProductBundleImpl.class, id);
        } else if (productBundle instanceof HibernateProxy) {
            deproxiedProductBundle = HibernateUtils.deproxy(productBundle);
        } else {
            deproxiedProductBundle = productBundle;
        }
    }
    return deproxiedProductBundle;
}
Also used : ProductBundleImpl(org.broadleafcommerce.core.catalog.domain.ProductBundleImpl) DefaultPostLoaderDao(org.broadleafcommerce.common.persistence.DefaultPostLoaderDao) PostLoaderDao(org.broadleafcommerce.common.persistence.PostLoaderDao) HibernateProxy(org.hibernate.proxy.HibernateProxy)

Example 68 with HibernateProxy

use of org.hibernate.proxy.HibernateProxy in project BroadleafCommerce by BroadleafCommerce.

the class DiscreteOrderItemImpl method getSku.

@Override
public Sku getSku() {
    if (deproxiedSku == null) {
        PostLoaderDao postLoaderDao = DefaultPostLoaderDao.getPostLoaderDao();
        if (postLoaderDao != null && sku.getId() != null) {
            Long id = sku.getId();
            deproxiedSku = postLoaderDao.find(SkuImpl.class, id);
        } else if (sku instanceof HibernateProxy) {
            deproxiedSku = HibernateUtils.deproxy(sku);
        } else {
            deproxiedSku = sku;
        }
    }
    return deproxiedSku;
}
Also used : SkuImpl(org.broadleafcommerce.core.catalog.domain.SkuImpl) DefaultPostLoaderDao(org.broadleafcommerce.common.persistence.DefaultPostLoaderDao) PostLoaderDao(org.broadleafcommerce.common.persistence.PostLoaderDao) HibernateProxy(org.hibernate.proxy.HibernateProxy)

Example 69 with HibernateProxy

use of org.hibernate.proxy.HibernateProxy in project hibernate-orm by hibernate.

the class FooBarTest method testProxiesInCollections.

@TestForIssue(jiraKey = "HHH-8662")
public void testProxiesInCollections() throws Exception {
    Session s = openSession();
    s.beginTransaction();
    Baz baz = new Baz();
    Bar bar = new Bar();
    Bar bar2 = new Bar();
    s.save(bar);
    Serializable bar2id = s.save(bar2);
    baz.setFooArray(new Foo[] { bar, bar2 });
    HashSet set = new HashSet();
    bar = new Bar();
    s.save(bar);
    set.add(bar);
    baz.setFooSet(set);
    set = new HashSet();
    set.add(new Bar());
    set.add(new Bar());
    baz.setCascadingBars(set);
    ArrayList list = new ArrayList();
    list.add(new Foo());
    baz.setFooBag(list);
    Serializable id = s.save(baz);
    Serializable bid = ((Bar) baz.getCascadingBars().iterator().next()).getKey();
    s.getTransaction().commit();
    s.close();
    s = openSession();
    s.beginTransaction();
    BarProxy barprox = (BarProxy) s.load(Bar.class, bid);
    BarProxy bar2prox = (BarProxy) s.load(Bar.class, bar2id);
    assertTrue(bar2prox instanceof HibernateProxy);
    assertTrue(barprox instanceof HibernateProxy);
    baz = (Baz) s.load(Baz.class, id);
    Iterator i = baz.getCascadingBars().iterator();
    BarProxy b1 = (BarProxy) i.next();
    BarProxy b2 = (BarProxy) i.next();
    // one-to-many
    assertTrue((b1 == barprox && !(b2 instanceof HibernateProxy)) || (b2 == barprox && !(b1 instanceof HibernateProxy)));
    // <many-to-many fetch="select" is deprecated by HHH-8662; so baz.getFooArray()[0] should not be a HibernateProxy.
    // many-to-many
    assertFalse(baz.getFooArray()[0] instanceof HibernateProxy);
    assertTrue(baz.getFooArray()[1] == bar2prox);
    // many-to-many outer-join="true"
    if (!isOuterJoinFetchingDisabled())
        assertTrue(!(baz.getFooBag().iterator().next() instanceof HibernateProxy));
    // one-to-many
    assertTrue(!(baz.getFooSet().iterator().next() instanceof HibernateProxy));
    doDelete(s, "from Baz");
    doDelete(s, "from Foo");
    s.getTransaction().commit();
    s.close();
}
Also used : Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) JoinedIterator(org.hibernate.internal.util.collections.JoinedIterator) Iterator(java.util.Iterator) HibernateProxy(org.hibernate.proxy.HibernateProxy) Session(org.hibernate.Session) HashSet(java.util.HashSet) TestForIssue(org.hibernate.testing.TestForIssue)

Example 70 with HibernateProxy

use of org.hibernate.proxy.HibernateProxy in project hibernate-orm by hibernate.

the class RelationNotAuditedTarget method testHistoryOfTnae1_id.

@Test
public void testHistoryOfTnae1_id() {
    // load original "tnae1" TargetNotAuditedEntity to force load "str1" UnversionedStrTestEntity as Proxy
    TargetNotAuditedEntity original = getEntityManager().find(TargetNotAuditedEntity.class, tnae1_id);
    UnversionedStrTestEntity uste1 = getEntityManager().find(UnversionedStrTestEntity.class, uste1_id);
    UnversionedStrTestEntity uste2 = getEntityManager().find(UnversionedStrTestEntity.class, uste2_id);
    TargetNotAuditedEntity rev1 = getAuditReader().find(TargetNotAuditedEntity.class, tnae1_id, 1);
    TargetNotAuditedEntity rev2 = getAuditReader().find(TargetNotAuditedEntity.class, tnae1_id, 2);
    TargetNotAuditedEntity rev3 = getAuditReader().find(TargetNotAuditedEntity.class, tnae1_id, 3);
    TargetNotAuditedEntity rev4 = getAuditReader().find(TargetNotAuditedEntity.class, tnae1_id, 4);
    assert rev1.getReference().equals(uste1);
    assert rev2.getReference().equals(uste2);
    assert rev3.getReference().equals(uste2);
    assert rev4.getReference().equals(uste1);
    assert original.getReference() instanceof HibernateProxy;
    assert UnversionedStrTestEntity.class.equals(Hibernate.getClass(original.getReference()));
    assert UnversionedStrTestEntity.class.equals(HibernateProxyHelper.getClassWithoutInitializingProxy(rev1.getReference()));
    assert UnversionedStrTestEntity.class.equals(Hibernate.getClass(rev1.getReference()));
}
Also used : UnversionedStrTestEntity(org.hibernate.envers.test.entities.UnversionedStrTestEntity) HibernateProxy(org.hibernate.proxy.HibernateProxy) TargetNotAuditedEntity(org.hibernate.envers.test.entities.manytoone.unidirectional.TargetNotAuditedEntity) Test(org.junit.Test)

Aggregations

HibernateProxy (org.hibernate.proxy.HibernateProxy)130 Session (org.hibernate.Session)58 Test (org.junit.Test)56 LazyInitializer (org.hibernate.proxy.LazyInitializer)33 DefaultPostLoaderDao (org.broadleafcommerce.common.persistence.DefaultPostLoaderDao)16 PostLoaderDao (org.broadleafcommerce.common.persistence.PostLoaderDao)16 EntityEntry (org.hibernate.engine.spi.EntityEntry)13 Serializable (java.io.Serializable)11 Transaction (org.hibernate.Transaction)10 TransientObjectException (org.hibernate.TransientObjectException)10 EntityPersister (org.hibernate.persister.entity.EntityPersister)10 HibernateException (org.hibernate.HibernateException)8 AdminPresentationMergeOverride (org.broadleafcommerce.common.presentation.override.AdminPresentationMergeOverride)5 EntityKey (org.hibernate.engine.spi.EntityKey)4 PersistenceContext (org.hibernate.engine.spi.PersistenceContext)4 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)4 Iterator (java.util.Iterator)3 ObjectDeletedException (org.hibernate.ObjectDeletedException)3 EventSource (org.hibernate.event.spi.EventSource)3 BigDecimal (java.math.BigDecimal)2