/** * Inject the identifier value into the given entity. * * @param entity The entity to inject with the identifier value. * @param id The value to be injected as the identifier. * @param session The session from which is requests originates * * @deprecated Use {@link #setIdentifier(Object, Serializable, SharedSessionContractImplementor)} instead */ @Deprecated default void setIdentifier(Object entity, Serializable id, SessionImplementor session) { setIdentifier( entity, id, (SharedSessionContractImplementor) session ); }
@Override public void setIdentifier(final Object object, final Serializable id) throws HibernateException { metadata.setIdentifier(object, id, getSessionImplementor()); }
public Object instantiate(final String entityName, final EntityMode entityMode, final Serializable id) throws CallbackException { if (LOG.isDebugEnabled()) { LOG.debug("instantiate entityName=" + entityName + ", id=" + id + ", mode=" + entityMode); } NakedObjectLoader loader = NakedObjectsContext.getObjectLoader(); HibernateOid oid = new HibernateOid(entityName, id); NakedObjectSpecification spec = NakedObjectsContext.getReflector().loadSpecification(entityName); NakedObject adapter = loader.recreateAdapterForPersistent(oid, spec); // TODO fudge to work around problem in getEntity where entity is a subclass // (HibernateOid doesn't handle subclasses!) if (adapter.getResolveState().isResolved()) { loader.start(adapter, ResolveState.UPDATING); } else { loader.start(adapter, ResolveState.RESOLVING); } Object object = adapter.getObject(); // need to set the id in case the object has an id property (if not id is held in // the oid, and that's taken care of above) try { HibernateUtil.getSessionFactory().getClassMetadata(entityName).setIdentifier(object, id, entityMode); } catch (HibernateException e) { throw new CallbackException("Error getting identifier property for class " + entityName, e); } return adapter.getObject(); }