Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Which hibernate property is causing the existing data to be deleted?

 
Saeed Amer
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

This is in relation to my previous post (re: hibernate.hbm2ddl.auto) but I thought to start a new thread and present the question in a different way. Maybe "hibernate.hbm2ddl.auto" has nothing to do with the issue I have.

The issue is that when I run my main method to test this simple Hibernate sample, all existing data in the table Honey is deleted. Following is my hibernate.cfg.xml. Could someone please tell me which property is causing the exiting data in the table to be deleted?



Here is my test class:



Here is what I see when I run the main method of my test class:



Look at the last line in output above - 0 row(s) found. There were few existing rows but after this run, they are gone. Not sure what is causing this.

Please look at lines 113-116. Since I have completely removed "hibernate.hbm2ddl.auto" property, what is causing this output now? Is it due to this part that my existing data is being deleted?

I am using Hibernate 3.3.1 and MySQL and perhaps needless to mention that I am a Hibernate-newbie.

Regards,

Saeed
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only thing in Hibernate that will overwrite your data is the hibernate.hbm2ddl stuff. You may have commented it out from the file you can see, but from the logs:

# 4-Jun-2009 10:02:45 AM org.hibernate.tool.hbm2ddl.SchemaExport execute
# INFO: schema export complete

Which looks like it is running. Did you deploy your change? Are you using the config file you think you are?
 
Saeed Amer
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul,

I have double checked and I have only one copy of hibernate.cfg.xml. And I am running this TestHoney's main method from within Eclipse (it is not a web app) so I guess possibility of not deploying correct hibernate.cfg.xml doesn't exist. This cfg file is exactly what I have posted above.

I still see following lines in the output:



Is it possible that Hibernate is using default value of this "hibernate.hbm2ddl.auto" property?

Thanks

Saeed
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, Hibernate doesn't behave that way.

Do you have a hibernate.properties file kicking around maybe?


And I am running this TestHoney's main method from within Eclipse (it is not a web app) so I guess possibility of not deploying correct hibernate.cfg.xml doesn't exist

Using eclipse doesn't assure this will be deployed correctly. When yopu biuld your applciation does eclipse copy hibernate.cfg.xml to where the code is run? You may also have to do a clean build if you've had a different config file in the past.
 
Paul Clapham
Sheriff
Pie
Posts: 20763
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Sturrock wrote:Using eclipse doesn't assure this will be deployed correctly. When yopu biuld your applciation does eclipse copy hibernate.cfg.xml to where the code is run? You may also have to do a clean build if you've had a different config file in the past.

And of course there's an easy way to tell what Eclipse actually deployed: you go to the place where you installed the web application and use a text editor to look at the hibernate.cfg.xml file.
 
Saeed Amer
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you both!

I have done the "Clean Build" already - made no difference.

I do not have any "hibernate.properties" file in the classpath although there are some copies of this file that came with the hibernate distribution.

I have verified that Eclipse copies the modified (updated) hibernate.cfg.xml file into the "bin" folder (where it keeps the compiled code). Both the XML files (in my "src" folder and the "bin" folder) are identical. I have also searched for other copies of hibernate.cfg.xml but there is none other the two (in src and bin folder). If I change the cfg file, and run the main method, I see that the updated file has been copied by Eclipse to the bin folder.

Since I am running main method from within Eclipse, I am not sure what does "deploy" mean in this scenario? I don't have a web application but it is a plain core java class that I am using to test and learn Hibernate.

Thank you both of you once again. If there is anything else I may try, please do let me know. I wanted to move forward and start developing the web app I am ultimately going to develop but if I stuck on this issue.

Regards
Saeed
 
Saeed Amer
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I believe I have solved the problem by making following change:

before:

after:


Now if someone could let me know which file would Hibernate look for (and where) by default if it is not mentioned as I did above, it will be great.

Thanks everyone.

Regards,
Saeed
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic