• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Create database schema from Hibernate?

 
Bai Shen
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know that there's a command that you can insert in the hibernate configuration file that will automatically create your database schema in the database for you when you run your program. But is there a way to get Hibernate to create a schema file for you? I forget the type of file. I just know that you can have a file which you import into a database and it creates your tables, etc.

This way when setting up a new installation of your program, you can just run the schema file instead of having to change the Hibernate config file and then change it back.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shcema file? This is not something I'm familiar with. Different databases have ways of restoring the schema only, but these are database specific and Hibernate is not going to support these.

Also, some databases will generate DDL from a schema. Again this is database specific and not something you can get Hibernate to do.

However, are you aware that the property hibernate.hbm2ddl.auto can take the value "update"? This will create the schema if its not already there, or apply changes if any have been made. If there are no changes it will change nothing. This might be what you are looking for?
 
Ridhav Mahajan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have never heard of as such thing, if you get to know anything about it, then do inform us But for opposite yes, i have used some plugins in eclipse WTP version to automatically generate the hibernate cfg files, In that case, there is separate option in "open perspective" called hibernate perspective which can be used further for automatic code generation.
 
Bai Shen
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Sturrock:
Shcema file? This is not something I'm familiar with. Different databases have ways of restoring the schema only, but these are database specific and Hibernate is not going to support these.

Also, some databases will generate DDL from a schema. Again this is database specific and not something you can get Hibernate to do.

However, are you aware that the property hibernate.hbm2ddl.auto can take the value "update"? This will create the schema if its not already there, or apply changes if any have been made. If there are no changes it will change nothing. This might be what you are looking for?


No, I didn't know about the update setting.

And a DDL may be what I'm thinking of. I'm not a DB guy, so I'm not sure what the correct terms are.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic