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.
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?
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 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.
Joined: Jan 20, 2004
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.
Joined: Jan 20, 2004
OK, I believe I have solved the problem by making following change:
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.