-->
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.  [ 2 posts ] 
Author Message
 Post subject: How to save the data into table forever
PostPosted: Fri Jun 13, 2008 11:34 am 
Newbie

Joined: Fri Jun 13, 2008 11:27 am
Posts: 6
I integrated hibernate with spring and save the in the dao impl class as the following,getHibernateTemplate().saveOrUpdate(Obj),when user click the save button of the web page,the method will called.But i found that the data will be in the table after the button is clicked only for a moment,after a while the data lost from the table,I don't know why?because of the transaction or other reasons?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 13, 2008 12:55 pm 
Beginner
Beginner

Joined: Tue Dec 12, 2006 6:43 am
Posts: 32
Location: London
Quote:
But i found that the data will be in the table after the button is clicked only for a moment


Hi,
As you mentioned above, the data is there for a moment. I guess your are not using HSQLDB (http://hsqldb.org with the in memmory connection.

The possible scenario is you are getting an Excpetion which is being digested ( swalloed) by Spring Framework. So you should catch the exception and see what is the problem; there is a possiblity that an exception is happening and the database is rolledback.
so the best thing is to report it to the standard outputStream or a File
In this way, you can know what is the problem.

Code:


public void saveChangeCase(final ChangeCase changeCase)
    {       
       
       
        HibernateTemplate template = getHibernateTemplate();
       
        template.execute(
                new HibernateCallback()
                {
                    public Object doInHibernate(Session session) throws HibernateException
                    {
                       
                    try {     
                       tx = session.beginTransaction();
                        session.saveUpdate(changeCase);
                        tx.commit();
                       
                       
                       }catch(HibernateException hiEx) {
          if(tx != null) {
          try {
            tx.rollback();
           }catch(HibernateException ex) {
                                                              ex.printStackTrace();
            throw ex;
           }
           throw hiEx;
        }
      }finally {
         try {
          session.close();
         }catch(HibernateException ex) {
                                                               ex.printStackTrace();
            throw ex;
         }
      }
                 
                       

                    }
                }
                );       
    }








The other possible scneario which I can see is in the hibernate configuration file with the propperty for autocommit

<property name="connection.autocommit">true</property>

]

_________________
Alan Mehio
London
UK


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.