-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Problem with refresh()
PostPosted: Wed Sep 26, 2007 9:42 am 
Beginner
Beginner

Joined: Tue Aug 21, 2007 4:58 am
Posts: 30
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;      
   }


Top
 Profile  
 
 Post subject: same problem
PostPosted: Fri Nov 02, 2007 10:22 am 
Beginner
Beginner

Joined: Wed Sep 14, 2005 9:11 am
Posts: 22
I am having the same problem. Did you find a solution? I have found that calling a get method on one of the attributes forces it to actually query to database, but that seems ugly:

<code>
LOG.debug("before sess.refresh(comment.getParent())");
sess.refresh(comment.getParent());
LOG.debug("after sess.refresh(comment.getParent())");
comment.getParent().getCreated();
LOG.debug("after comment.getParent().getCreated();");
</code>

<output>
2007-11-02 09:10:12,845 DEBUG [http-8080-Processor25] dao.CommentDao$1 (CommentDao.java:30) - before sess.refresh(comment.getParent())

2007-11-02 09:10:12,845 DEBUG [http-8080-Processor25] dao.CommentDao$1 (CommentDao.java:32) - after sess.refresh(comment.getParent())

2007-11-02 09:10:12,845 DEBUG [http-8080-Processor25] jdbc.AbstractBatcher (AbstractBatcher.java:401) -
/* load com.textwise.festoon.data.Comment */ select
comment0_.id as id1_0_,
comment0_.parentId as parentId1_0_,
comment0_.threadId as threadId1_0_,
comment0_.text as text1_0_,
comment0_.userId as userId1_0_,
comment0_.created as created1_0_,
comment0_.modified as modified1_0_,
comment0_.status as status1_0_
from
comments comment0_
where
comment0_.id=?
and (
comment0_.status = 0
)
</output>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 23, 2007 6:04 pm 
Newbie

Joined: Fri Nov 23, 2007 5:23 pm
Posts: 5
I am also the exact same issue also.

Calling the getters in conjunction with System.out.println() prints out the values, but viewing the values using the Eclipse debugger shows that they are null.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.