-->
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: Problem with update statements
PostPosted: Fri Feb 13, 2009 6:53 pm 
Newbie

Joined: Fri Feb 13, 2009 6:40 pm
Posts: 6
Hi

I am trying to update a table in SQL Server database using Hibernate and Struts.
I used the statement :

Session session = null;
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session = sessionFactory.openSession();
int in = session.createQuery("update Chem c set c.min= :min where c.element =:element").setString("min", form.getMin()).setString("element", form.getElement()).executeUpdate();
session.flush();
if(in!=0) grade="success";
session.close();


I have a JSP page with text fields for element and min with properties element and min respectively. I already have values for these fields in the database which are shown when I first load the page.

When I am trying to change the values, the following problems occur:

a) the values are not getting updated in the database.
b) When I try to see the updated results in the JSP page, it just gets stuck when loading the page and it doesnt show me the page.

I have flushed the session and i have closed the session. I cant understand why it is taking so much time to load and why it is not updating values in the database.

Can someone help me out?

Thanks
Neeti


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2009 7:16 pm 
Newbie

Joined: Fri Feb 13, 2009 6:40 pm
Posts: 6
Hi

Update worked with Transaction. I made changes to the code like :

Session session = null;
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
int in = session.createQuery("update Chem c set c.min= :min where c.element =:element").setString("min", form.getMin()).setString("element", form.getElement()).executeUpdate();
tx.commit(); // instead of session.flush();
if(in!=0) grade="success";
session.close();


Why does it not work with session.flush()? I saw in Hibernate.org in the FAQ that you can use both ways.

Can somebody help with this?

thanks
Neeti


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.