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
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'test.person' doesn't exist
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
please change the code from:
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
to :
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
try it.
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.
Is there a space between "property" and "name"?
<propertyname="hibernate.hbm2ddl.auto">create</property>
If not, then that's probably the issue. Also, what do you mean that it fixes when you "reboot the MySQL database"? Does it means you just restart the MySQL server, or it means that you need to manually recreate the table? Also, if the XML excerpt above indeed contains an space between "property" and "name", please provide also the except for the hibernate logs, specially the part that it lists all the properties it identified.
Please change the code from:
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
to :
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
Try it. It really worked in my case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With