I am using Hibernate to develop web application.I have a point that after saving values from my web application to database in localhost.When I undeploy application from my localhost.All values in saved database are also being deleted.However table structure is there but values are empty?
No, it's not! I asked 2 pretty straightforward questions. You replied with a very lengthy post but it doesn't answer either of my questions...
I also wonder why you have a Dao class for updating and another one for creating. I have never seen this approach. You have a Dao interface (and implementing class) with CRUD methods.
I also wonder why you have a Dao class for updating and another one for creating. I have never seen this approach. You have a Dao interface (and implementing class) with CRUD methods.
because if i will use only create command then it will always create a new table previous record will be delete.
If I use only update when first time I run I will get exception that table not exists.
So I have made a custom logic if request is first time or already a table is created.
I would never rely on hbm2ddl in a production environment. It's ok for development purposes, but a risk for a production envorinment. I always create my database scripts manually and execute them manually.
And it seems it's not only me who doesn't want to rely on hbm2ddl in a production environment. Here and here you'll find more user experiences.
write the ddl statements (to create/alter tables and other database objects) yourself and execute them manually
don't use hbm2ddl in your application
write 1 Dao for each entity with create, read, update, delete, find and other required methods
consider Spring to handle transaction management using annotation instead of creating transactions in the code yourself. And if you do, consider Spring Data JPA as well.
As for why Hibernate recreates empty database tables before each run (if that's what's actually happening): there's a configuration property which tells Hibernate to do that (or not). It's this one, if I'm not mistaken: