jQuery in Action, 3rd edition
The moose likes Object Relational Mapping and the fly likes Hibernate replacing my tables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate replacing my tables" Watch "Hibernate replacing my tables" New topic

Hibernate replacing my tables

Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962

Why is Hibernate replacing existing tables in the database with its own, different tables upon a call to session.find("from X")?

Here's my mapping document:

Here's the class I'm mapping:

And this is what I used for creating the table before triggering the SELECT from within Tomcat:

Note that I've included a 'password' column in the database and that isn't mapped to the User class.

Finally, this is what happens when Hibernate has had a chance to do the SELECT:

I'd really appreciate any pointers towards where I'm going to the woods.

I'm using Hibernate 2.1.6 and MySQL 4.0.22.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Alexandru Popescu
Ranch Hand

Joined: Jul 12, 2004
Posts: 995
Lasse I think you have enabled the hibernate.hbm2ddl.auto property set to create-drop. This will create and drop the tables each time you create a SessionFactory. Have a look in chapter 3.5


blog - InfoQ.com
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
Thanks for the tip. I had already spotted that one from the bottom of the mile-long hibernate.properties which I had copy-pasted from somewhere but forgot to post here...
It is sorta covered in the JavaRanch Style Guide.
subject: Hibernate replacing my tables
It's not a secret anymore!