List of usage examples for org.hibernate.persister.entity EntityPersister getDatabaseSnapshot
Object[] getDatabaseSnapshot(Serializable id, SharedSessionContractImplementor session)
throws HibernateException;
From source file:com.autobizlogic.abl.hibernate.HibernateUtil.java
License:Open Source License
/** * Given a persistent bean, get (if available) the values originally loaded from the database * when the object was read./* w w w. j a va2 s . co m*/ * @param bean The persistent bean (must be Pojo) * @param session The current Hibernate session * @return Null if the object is not known by Hibernate, otherwise an ObjectState with the original * values. */ public static PersistentBean getOldStateForObject(Object bean, Session session) { if (!session.contains(bean)) return null; Serializable pk = session.getIdentifier(bean); Class<?> beanClass = getEntityClassForBean(bean); String beanClassName = beanClass.getName(); EntityPersister persister = HibernateSessionUtil.getEntityPersister(session, beanClassName, bean); Object[] cachedValues = persister.getDatabaseSnapshot(pk, (SessionImplementor) session); return HibPersistentBeanFactory.createPersistentBeanCopyFromState(cachedValues, bean, persister, session); }