Win a copy of High Performance Python for Data Analytics this week in the Python forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

How this is happening in Hibernate?

 
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there

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?

Why this is happening?

Thanks
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And are you sure the data is actually in the database (table) after saving the values (and before undeploying the application)?

And what kind of database are you using? MySQL? Oracle? Or an in-memory database perhaps?
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok this post might be lengthy

This is my model class


This is my bean.xml file



This is my dao Impl class


and this is MyServlet code from where I am calling this Dao method


I hope know its more clear
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kishor Joshi wrote:I hope know its more clear


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.
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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.
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Hope it helps!
Kind regards,
Roel
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So what you suggest in my case to change this ?
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 26317
80
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I will update my post soon on this topic
 
and POOF! You're gone! But look, this tiny ad is still here:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic