需要清楚hibernate.hbm2ddl.auto = update [英] Need clarity on hibernate.hbm2ddl.auto=update

查看:139
本文介绍了需要清楚hibernate.hbm2ddl.auto = update的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用hibernate和java来创建和管理关系数据库MySQL。现在我陷入了先前创建表的情况,这些表也包含数据。
我目前的要求是我需要增加列的大小。早些时候,我给了java.lang.String类型的大小50,但现在我需要增加并使其成为80.有没有什么办法可以在休眠状态下执行此操作?
我无法使用 hibernate.hbm2ddl.auto = create ,因为它会截断表中的整个数据并直接从数据库级别更新它,在我的情况下不可行。在这种情况下,我不认为需要清楚 hibernate.hbm2ddl.auto = update 会对我有所帮助。请建议是否有任何方法可以在休眠状态下执行此操作。提前致谢..

I am using hibernate and java to create and manage relational database MySQL. Now I am stuck in the situation where tables has been created earlier and these table are containing data too. My current requirement is that I need to increase size of column. Earlier I have given size 50 for java.lang.String type but now I need to increase and make it 80. Is there any way in hibernate by which I can do this ? I can't use hibernate.hbm2ddl.auto=create because it will truncate entire data in table and update it directly from database level is not feasible in my case. I don't think Need clarity on hibernate.hbm2ddl.auto=update is going to help me in this case. Please suggest if there is any way in hibernate by which I can do this. Thanks in advance..

推荐答案

设置 hiberate.hbm2ddl.auto = validate 并使用MySQLWorkbench或任何类似工具手动更改实际数据库中列的大小。另请参阅此处,了解有关不同的解释值做。这是如果你真的想保持数据库中的数据持久。我敢肯定,使用 update 仍然会删除整个表来替换列长度,所以我不会使用它。使用 validate 会导致Hibernate根据注释验证数据库模式,以确保数据库设置正确。永远不会使用 validate 以外的其他产品代码。

Set hiberate.hbm2ddl.auto=validate and manually change the size of the column on the actual database yourself using MySQLWorkbench or any similar tool. Also see here for an explanation on what the different values do. This is if you actually want to keep the data in the database persisted. I'm pretty sure that using update will still drop the entire table to replace the column length so I wouldn't use that. Using validate will cause Hibernate to validate your database schema against your annotations to ensure that your database is set up correctly. Never ever ever ever use anything other than validate for production code.

编辑:
要真正回答这个问题,没有Hibernate不能删除和重新创建表,这将导致那里的任何数据丢失。

To actually answer the question, no Hibernate cannot do this without dropping and re-creating the table, which will cause any data in there to be lost.

这篇关于需要清楚hibernate.hbm2ddl.auto = update的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆