开发者

Java JPA, How to do Updates to a table without destroy-create?

开发者 https://www.devze.com 2023-01-21 14:52 出处:网络
I was learning some JPA to teach to some java friends and I was wondering, how do you handle updates that comes after the creation of the db in JPA? Let\'s say I have a production environment where th

I was learning some JPA to teach to some java friends and I was wondering, how do you handle updates that comes after the creation of the db in JPA? Let's say I have a production environment where there's data that I cannot lose.

Some changes comes in and how do I apply that on my production environment? It there a way开发者_JAVA百科 that JPA would only update the changes on the database?

Or do I need to manually create a SQL script to update my database?

Is there any other options?

[]'s Rodrigo Dellacqua


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?

Nothing standardized. In other words, that would be a provider specific feature. For example, Hibernate has a SchemaUpdate tool that can (in theory) safely update a database schema. In practice, many don't use that on a production database (including me).

Or do I need to manually create a SQL script to update my database?

Using migration scripts (and maybe a database migration tool) is IMO the safe way to handle this and is the way to go on real life projects.

And again, some migration tools might provide support for a given JPA provider. For example, liquibase does offer Hibernate support and can diff your Entities against a database to generate a change script.

0

精彩评论

暂无评论...
验证码 换一张
取 消