List of usage examples for org.hibernate.proxy HibernateProxyHelper getClassWithoutInitializingProxy
public static Class getClassWithoutInitializingProxy(Object object)
From source file:com.brienwheeler.lib.db.domain.GeneratedIdEntityBase.java
License:Open Source License
/** * @return true if obj is the same JVM object as this, or obj and this are * both persisted database objects of the same class with the same id. *///from w w w.j a v a2s . c o m @Override public boolean equals(Object obj) { return (this == obj) || (obj != null) && HibernateProxyHelper.getClassWithoutInitializingProxy(this) .equals(HibernateProxyHelper.getClassWithoutInitializingProxy(obj)) && (getId() != 0) && (getId() == ((GeneratedIdEntityBase<?>) obj).getId()); }
From source file:com.ejushang.steward.common.genericdao.search.hibernate.HibernateMetadataUtil.java
License:Apache License
public <T> Class<T> getUnproxiedClass(Object entity) { return HibernateProxyHelper.getClassWithoutInitializingProxy(entity); }
From source file:com.mycompany.bookstore.entity.BaseEntity2.java
@SuppressWarnings("unchecked") @Override/*from ww w . ja v a 2s . c om*/ public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof BaseEntity2)) { return false; } if (getId() == null || ((BaseEntity2<?>) obj).getId() == null) { return false; } if (!getId().equals(((BaseEntity2<?>) obj).getId())) { return false; } if (!HibernateProxyHelper.getClassWithoutInitializingProxy(obj).isAssignableFrom(this.getClass())) { return false; } return true; }
From source file:com.utest.dao.TypelessHibernateDAOImpl.java
License:Apache License
/** * Resolve entities if not defined in skipEntities_ collection * //from w w w .j a va 2 s.c o m * @param entity_ * @param arrayList * @return */ @SuppressWarnings("unchecked") private Object resolveDeepProxies(final Object entity_, final ArrayList<Class<?>> arrayList, final Collection<String> resolvedEntities_) { // if not found object if (entity_ == null) { return entity_; } Class<? extends Object> clazz; if (entity_ instanceof HibernateProxy) { clazz = HibernateProxyHelper.getClassWithoutInitializingProxy(entity_); } else { clazz = entity_.getClass(); } loadLazyObject(entity_); final ClassMetadata metadata = this.getSessionFactory().getClassMetadata(clazz); if (metadata != null) { final String[] propertyNames = metadata.getPropertyNames(); final Type[] propertyTypes = metadata.getPropertyTypes(); String propName = null; Type propType = null; // recursively resolve all child associations for (int i = 0; i < propertyNames.length; i++) { propName = propertyNames[i]; propType = propertyTypes[i]; // many-to-one and one-to-one associations if (propType.isEntityType()) { Object assoc = metadata.getPropertyValue(entity_, propName, EntityMode.POJO); Hibernate.initialize(assoc); if (assoc != null) { assoc = resolveDeepProxies(assoc, arrayList, resolvedEntities_); metadata.setPropertyValue(entity_, propName, assoc, EntityMode.POJO); } } // one-to-many associations else if (propType.isCollectionType()) { // PersistentMap (Collection<Object>) final Object children = metadata.getPropertyValue(entity_, propName, EntityMode.POJO); if (children instanceof Collection) { Hibernate.initialize(children); if (children != null) { final Collection<Object> resolvedChildren = new ArrayList(); for (final Object child : ((Collection) children)) { final Object resolvedChild = resolveDeepProxies(child, arrayList, resolvedEntities_); resolvedChildren.add(resolvedChild); } metadata.setPropertyValue(entity_, propName, resolvedChildren, EntityMode.POJO); } } } } } // resolve Parent object return loadLazyObject(entity_); }
From source file:de.tudarmstadt.ukp.clarin.webanno.support.EntityModel.java
License:Apache License
private void analyze(T aObject) { if (aObject != null) { entityClass = HibernateProxyHelper.getClassWithoutInitializingProxy(aObject); String idProperty = null; Metamodel metamodel = getEntityManager().getMetamodel(); EntityType entity = metamodel.entity(entityClass); Set<SingularAttribute> singularAttributes = entity.getSingularAttributes(); for (SingularAttribute singularAttribute : singularAttributes) { if (singularAttribute.isId()) { idProperty = singularAttribute.getName(); break; }/* w w w .j ava 2s . c om*/ } if (idProperty == null) { throw new RuntimeException("id field not found"); } DirectFieldAccessor accessor = new DirectFieldAccessor(aObject); id = (Number) accessor.getPropertyValue(idProperty); } else { entityClass = null; id = null; } }
From source file:edu.harvard.med.screensaver.model.AbstractEntity.java
License:Open Source License
@SuppressWarnings("unchecked") @Transient//from ww w . j a v a 2 s. c o m final public Class<Entity<K>> getEntityClass() { return HibernateProxyHelper.getClassWithoutInitializingProxy(this); }
From source file:net.databinder.models.hib.HibernateObjectModel.java
License:Open Source License
/** * Change the persistent object contained in this model. * Because this method establishes a persistent object ID, queries and binders * are removed if present.//from w w w . j a v a 2 s. c o m * @param object must be an entity contained in the current Hibernate session, or Serializable, or null */ public void setObject(T object) { unbind(); // clear everything but class, name objectClass = null; if (object != null) { objectClass = HibernateProxyHelper.getClassWithoutInitializingProxy(object); Session sess = Databinder.getHibernateSession(factoryKey); if (sess.contains(object)) objectId = sess.getIdentifier(object); else if (retainUnsaved) retainedObject = (T) object; setTempModelObject(object); // skip calling load later } }
From source file:org.bonitasoft.engine.business.data.impl.BusinessDataReloader.java
License:Open Source License
public Class getEntityRealClass(Entity entity) { return HibernateProxyHelper.getClassWithoutInitializingProxy(ServerProxyfier.unProxifyIfNeeded(entity)); }
From source file:org.cateproject.domain.Base.java
@Override public boolean equals(Object other) { if (this == other) { return true; }/* w ww . ja v a 2s . c o m*/ if (other == null) { return false; } if (HibernateProxyHelper.getClassWithoutInitializingProxy(other).equals(this.getClass())) { Base base = (Base) other; return ObjectUtils.equals(this.getIdentifier(), base.getIdentifier()); } else { return false; } }
From source file:org.codehaus.groovy.grails.orm.hibernate.proxy.HibernateProxyHandler.java
License:Apache License
public Class<?> getProxiedClass(Object o) { return HibernateProxyHelper.getClassWithoutInitializingProxy(o); }