简体   繁体   中英

Does hibernate “auto schema update” drop anything it doesn't own?

I have multiple projects each with their own entities, indexes, etc (using spring-data but the underlying JPA provider is Hibernate 5.0.12). Lets say project A has entities/tables T and U, and project B has entities/tables V and W, and both projects are connecting to the same MySQL database. If I set hibernate.ddl-auto: update on each of the projects would these projects ever interfere with each other? Would project A ever see tables V and W and think "hey, those tables aren't in my schema, I'll get rid of them"?

Are there any other gotchas I should be aware of when connecting multiple hibernate schemas with auto-update to the same MySQL database? Eventually when we do our production deployment we will create one big unified "model" project and all projects will have it as a dependency, but while we're prototyping it is way quicker just to chuck the necessary entities into the relevant project - but not if it'll cause problems!

i highly advise you to read more about this here: https://docs.spring.io/spring-boot/docs/current/reference/html/howto-database-initialization.html

but to answer your question: No, it will not drop anything. .

The update procedure will search for all columns that it can create and then create those. Not even changing a database type (from int to string, for example) is possible.

In such scenarios, it is highly advisable to use a tool like Flyway or Liquibase. https://flywaydb.org https://www.liquibase.org

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM