我正在学习一些 JPA 来教一些 java friend ,我想知道,在 JPA 中创建数据库后如何处理更新?假设我有一个生产环境,其中的数据不能丢失。
发生了一些变化,我如何将其应用到我的生产环境中? JPA 有没有办法只更新数据库上的更改?
或者我是否需要手动创建 SQL 脚本来更新我的数据库?
还有其他选择吗?
[]的 罗德里戈·德拉夸
最佳答案
Some changes comes in and how do I apply that on my production environment? It there a way that JPA would only update the changes on the database?
没有任何标准化。换句话说,这将是提供商特定的功能。例如,Hibernate 有一个 SchemaUpdate 工具,理论上可以安全地更新数据库架构。在实践中,many don't use that on a production database (包括我)。
Or do I need to manually create a SQL script to update my database?
使用迁移脚本(也许是 database migration tool )是 IMO 处理此问题的安全方法,也是进行现实生活项目的方法。
同样,某些迁移工具可能会为给定的 JPA 提供程序提供支持。例如,liquibase确实提供 Hibernate support和 can diff your Entities against a database to generate a change script .
关于Java JPA,如何在不破坏-创建的情况下更新表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3991803/