问题描述
在配置hibernate.cfg.xml中,我添加了
我不相信使用 create 会更新就地模式,添加您删除的表。尝试:
< property name =hibernate.hbm2ddl.auto>更新< / property>
这是创建一个模式(如果不存在的话),并尝试修改现有模式以匹配您已定义的映射。
另外,阅读关于所有可能的值。
In configuration hibernate.cfg.xml, i add<property name="hibernate.hbm2ddl.auto">create</property>Hibernate do create table automatically when i run the application. However, i remove the table from database manually by running drop table sql. Then run the hibernate application again. The exception appear
only way to fix the problem is restart the Mysql database. Could anyone explain this issue for me?
this is my hibernate.cfg.xml
<hibernate-configuration> <session-factory> <property name="hibernate.connection.driver_class"> com.mysql.jdbc.Driver </property> <property name="hibernate.connection.url"> jdbc:mysql://localhost/test </property> <property name="connection.username">root</property> <property name="connection.password">root</property> <property name="dialect"> org.hibernate.dialect.MySQLDialect </property> <!-- Drop and re-create the database schema on startup --> <property name="hibernate.hbm2ddl.auto">create</property> <!-- Enable Hibernate's automatic session context management --> <property name="current_session_context_class">thread</property> <!-- Disable the second-level cache --> <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property> <!-- Echo all executed SQL to stdout --> <property name="show_sql">true</property> <!-- Mapping files --> <mapping resource="com/mapping/Event.hbm.xml" /> <mapping resource="com/mapping/Person.hbm.xml"/> </session-factory>
Thx
I don't believe using create will update an in-place schema to re-add the table that you dropped. Try:
<property name="hibernate.hbm2ddl.auto">update</property>
This is create a schema if one doesn't exist, and attempt to modify an existing one to match the mapping you have defined.
Also, read this question about all the possible values.
这篇关于hibernate表不存在错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!