• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

hibernate_struts_tomcat

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the problem you are having?
 
subha nair
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 .
reply
    Bookmark Topic Watch Topic
  • New Topic