Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hibernate_struts_tomcat

 
subha nair
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public static void add(Student student){

SessionFactory session = HibernateUtil.getSessionFactory();
Session sess = session.getCurrentSession();
org.hibernate.Transaction tx=sess.beginTransaction();
try
{
sess.save(student);
System.out.println("record inserted");

}
catch (HibernateException e)
{
System.err.println("Hibernate Exception" + e.getMessage());
throw new RuntimeException(e);
}
finally {

tx.commit();

}

}


Help me plzzzzz
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the problem you are having?
 
subha nair
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry,
I am using the above code to put data to mysql using hibernate.
It is getting stored in the database.But when I restart my server, the old values are gone and only new values get stored.
I am using struts,hibernate,tomcat.

if first I had 3 values. then after restarting the server, the three values are gone. they are not persisting in the database.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How did you verify they were in the database? If you connected via a sql client after the insert has happened and can see the inserted records, then something else is deleting them. This is not normal behaviour for Hibernate, unless you are getting Hibernate to generate your schema? If you are, the table will be being dropped and recreated when your application starts.
 
subha nair
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for the reply.
In cfg.xml. I had accidently put
<property name="hbm2ddl.auto">create</property>
I changed the create to update.

Thanks.I have got another doubt.Could you sort it out

I wanted to edit the values previously stored in the database.
I am using struts with hibernate for it.
I have used a dispatchaction class where I have written add,delete and edit code.
each operation is calling another method where the database calls are done.
the vaues read from the database are stored in the arraylist, and they are passsed to the actionclass .then these are passed to jsp page to display the values.Is there any other effective
way to do the application rather than passing collection through pages. I was told that it affects performance, if session object that stores collections are passed over .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic