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;
}
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;
}
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;
}
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();
}
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()));
}
Aggregations