I have one issue though. When I run the application, Hibernate either drops and re-creates the table (<property name="hibernate.hbm2ddl.auto">create</property>) OR it deletes all the existing data (when <property name="hibernate.hbm2ddl.auto">validate</property>). I have tried removing this property altogether but Hibernate still deletes (truncates) the data in the table each time I run the test application. Here is the hibernate.cfg.xml:
And here is my Honey.hbm.xml:
Here is the test class:
Honey class is simple POJO and I am using MySQL to store the data. I hope I haven't missed any details.
Could someone please tell me what Hibernate configuration should I use so that when I run "TestHoney", old data remains in the table.
Thanks!
Saeed
Cameron Wallace McKenzie
,
author and cow tipper
staff
I removed the line (previously I tried by commenting it out - I guess it is same as removing it) but the result is the same. In my TestHoney class (listed above), I am only inserting rows and then listing them. So, for each run, I should see 6 rows added to previous count but I only see 6-rows. Which means, this change made no difference. Here is modified hibernate.cfg.xml:
There is only one copy of this file in the classpath. Any other thoughts?
And yes, I am a newbie and I am absolutely going to go through your Hibernate guide/tutorial.
Thanks again and if there is anything else I may try to fix this problem, please do let me know.
I have already tried this option too but it did not make any difference.
I solved the problem by replacing following line with the one below it:
Modified line:
So I am not sure which configuration OR properties file Hibernate was reading before this change. Perhaps that is why setting "hibernate.hbm2ddl.auto" to "update" didn't work.
I checked my classpath and there was no properties file and there was only one copy of configuration file (one copy of same file in the bin folder copied by Eclipse).
Do you know how can I check which file was Hibernate using?
Thank you!
Saeed
Cameron Wallace McKenzie
,
author and cow tipper
staff
Cameron Wallace McKenzie wrote:
And make sure you don't have more than one hibernate config file on your classpath. In that case, Hibernate might be going to the wrong file.
I just had a hunch!
You know, I might just do a search on your classpath for hibernate config files and see if there are any others. Your JVM must be picking one up from somewhere else on your classpath. This change is instructing the classloader to look local.
That's a very frustrating problem. I hope it doesn't sour your Hibernate experience. It really wasn't all Hibernate's fault.
Was there any source change management tool locking the updates and forcing you to use a previous version? I've seen that happen.
I am also glad it worked but I wonder the way I fixed it is the right way to do it or not?
I searched for properties and configuration files on my computer and there was no other copy of hibernate.cfg.xml except for the one in "src" folder and an identical copy in the "bin" folder (copied by Eclipse). The only copies of "hibernate.properties" files were the ones that came with the Hibernate distribution and these directories (where I unzipped them) are not on my classpath.
I still wonder if there is a way to "ask" hibernate which configuration/properties file it was look at (even if it was not hibernate's fault :-) )? I'll do some search to find the answer to this question but if you can point me in the right direction, it will save me valuable time.
Thank you Cameron and thank you everyone else who responded and helped.
Regards,
Saeed
Cameron Wallace McKenzie
,
author and cow tipper
staff
At runtime, it will be picking up the copy in the bin directory. The editor works on the copy in the src directory.
I think there's a chance that the config file in the src directory wasn't being copied into the bin directory during build/compile time or runtime. Thus, your src and bin files may have been out of sync.
-Cameron McKenzie
Post by:autobot
I'm doing laundry! Look how clean this tiny ad is:
a bit of art, as a gift, the permaculture playing cards