在休眠启动时删除所有表 [英] Drop all tables at hibernate startup
问题描述
出于开发目的,如何配置休眠方式使其在运行之前删除所有表?我不想在运行代码之前不断手工删除所有表.
How can I configure hibernate in a way that it DROPS all tables before it runs, for developement purposes? I don't want to constantly DROP all tables by hand before running my code.
我已经在使用
<property name="hbm2ddl.auto">create</property>
但这似乎不起作用,因为我遇到了一些错误,这些错误是由先前运行中的错误模式引起的.
But this does not seem to work, since I ran into several errors that where caused by wrong schemas from a previous run.
修改 也许我的问题有点误导.我想要一个干净的数据库.这不仅是因为实际的运行时错误,而且还因为每次运行都拥有一个干净的数据库.
Edit Maybe my questions was a bit missleading. I want to have a clean database. Its not only because of actual runtime errors but also about having a clean database for every run.
<property name="hbm2ddl.auto">create-drop</property>
忽略无法休眠的表(如果您正在使用表名,这种情况可能会经常发生).
Ignores tables that are unknown to hibernate (which can happen quite often if you are playing around with tablenames).
推荐答案
使用值create-drop
代替create
这篇关于在休眠启动时删除所有表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!