Firstly, I will explain what it is my problem. I have several objects which need to keep track of its history. Everytime I save a change I have to create a history object and then modify it. The thing is that I modify the object and then i get the cop from the data base. In order to do this I have to play arround with the evict method. The problem comes when I try to load the old object from the data base calling refresh(), because it doen´t load all the attributes, in fact all attributes are null. After that, when I reassociate the modified object to the session, using lock(newObject, lockmode.none), when I save, it doesn´t do it.
any ideas???
Code:
protected BaseModelo getFisico(BaseModelo objetoActual) {
      //Si no sacamos el objeto actual de la session da error el refresh
      getHibernateSession().contains(objetoActual);
      getHibernateTemplate().evict(objetoActual);
      getHibernateSession().contains(objetoActual);
      BaseModelo objetoFisico = null;
      try {
         objetoFisico = objetoActual.getClass().newInstance();
      } catch (InstantiationException e) {
         throw new DAOPadronException(e);
      } catch (IllegalAccessException e) {
         throw new DAOPadronException(e);
      }
      objetoFisico.setId(objetoActual.getId());
      getHibernateSession().refresh(objetoFisico);
      // Control de error en la recuperación del objeto real de la BD
      assert objetoActual != objetoFisico : "No se ha recuperado el objeto actualizado de la base de datos";
      //Sacamos el objeto de Fisico de la session para al actualizar el id no de error al salvar.
      getHibernateTemplate().evict(objetoFisico);
      //Lo he sacado de sesion y lo vuelvo a meter para que no me de problemas el lazy
      getHibernateSession().lock(objetoActual, LockMode.NONE);
      return objetoFisico;      
   }