hibernate表不存在错误

在配置hibernate.cfg.xml中,我添加 <property

name="hibernate.hbm2ddl.auto">create</property>

Hibernate并在运行应用程序时自动创建表。但是,我通过运行drop table sql从数据库中手动删除该表。然后再次运行hibernate应用程序。出现异常

引起原因:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:表’test.person’不存在

解决该问题的唯一方法是重新启动Mysql数据库。谁能为我解释这个问题?

这是我的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>

谢谢

回答:

我不相信使用create会更新就地架构以重新添加您删除的表。尝试:

<property name="hibernate.hbm2ddl.auto">update</property>

如果不存在,则创建一个架构,并尝试修改现有的架构以匹配您定义的映射。

以上是 hibernate表不存在错误 的全部内容, 来源链接: utcz.com/qa/406113.html

回到顶部