-->
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: data updated/not updated?
PostPosted: Thu Dec 06, 2007 11:13 pm 
Newbie

Joined: Thu Dec 06, 2007 10:56 pm
Posts: 2
Hibernate version: 3.2
Struts 1.3.5

Hi there,
I want to ask something about struts and hibernate. Here i have some code to update my data. It would be like this:

Code:
public void updateTopicReply(Integer id,Integer reply) {

Topic topic = null;
Session session = null;
Transaction tx = null;
session = HibernateSessionFactory.currentSession();

reply=reply+1;
topic = (Topic) session.get(Topic.class, id);
topic.setReply(reply);
tx = session.beginTransaction();
session.update(topic);
tx.commit();
session.close();

}


when i saw it again in my jsp, no its not changed. But when I press F5, yeaaaa, it's been updated.
But when i press F5 again, it changed back again. And I keep press F5, it's just like the lamp of a christmas tree...

So i read some more and I try to add this flush() and refresh()

Code:
...
tx = session.beginTransaction();
session.update(topic);
session.flush();
session.refresh(topic);
tx.commit();
...



But, man.It's still the same.

Anyone know what is the problem?
Any idea or solution u can share?
Or any other method to give?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 07, 2007 3:05 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
This is strange. Try to use seperate session to retrieve and update.

public void updateTopicReply(Integer id,Integer reply) {

Topic topic = null;
Session session = null;
Transaction tx = null;
// For retrievel
session = HibernateSessionFactory.currentSession();
topic = (Topic) session.get(Topic.class, id);
session.close();

//For update
session1 = HibernateSessionFactory.currentSession();
reply=reply+1;
topic.setReply(reply);
tx = session1.beginTransaction();
session1.update(topic);
tx.commit();
session1.flush();
session1.close();
}

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject: my mistake
PostPosted: Mon Dec 10, 2007 9:52 pm 
Newbie

Joined: Thu Dec 06, 2007 10:56 pm
Posts: 2
Haha, ignore my question above.
Nothing wrong with that code, it's just me, not closing my other session before.

To much pressure i guess, learning struts, hibernate and java from zero to make a forum app in 3 week

Thx


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.