How to create a database schema using Hibernate

After reading Hibernate: hbm2ddl.auto = update in production? some questions have arisen. First of all, the reason that I use Hibernate is an independent database provider (there is no need to write 10 versions of a “single” SQL query, for example, tsql vs sql).

My problem arises when I need to create database schemas (production environment). As far as I can see, I have two alternatives.

  • hbm2dll = update
  • pure sql (ddl) scripts.

The first option is widely discussed in the stream above. The second option is bad, because it means that I returned to my first problem: "I do not want to create SQL queries that depend on the database provider." (This statement may not be true if "everything" (currently Hibernate database support) implements DDL (a subset of SQL used to define and examine the database structure.) Is equal).

+5
source share
4 answers

/, ( , ). , hbm2ddl .

hibernate ddl . hbm2ddl :

org.hibernate.tool.hbm2ddl.SchemaExport --config=hibernate.cfg.xml --text --format --delimiter=;

org.hibernate.tool.hbm2ddl.SchemaUpdate --config=hibernate.cfg.xml --text --format --delimiter=;
+5

, JPA, SchemaExport, .

Maven/ Gradle https://github.com/Devskiller/jpa2ddl, JPA. , , ..

Flyway.

+3

Hibernate (LOT), , , , -. - , , , - .

My suggestion would be in a test environment to have sleep mode generate database schemas. Check out those in the test environment. Then transfer these scripts to the production environment and run them. Pay attention to the specifics there; even if the tests succeed fantastically, STILL didn’t just let Hibernate play out on the production server. Take the output of the Hibernate circuit, test it after checking it, then deploy it to the production server.

+1
source

All Articles