不能自動創(chuàng)建表,保存報錯。手動創(chuàng)建表,保存沒有問題。
?求助hibernate不能自動建表,mysql版本5.1.42,hibernate3.方言配置:(我試過很多個方言MySQLInnoDBDialect ?MySQL5InnoDBDialect ? MySQL5Dialect ?HSQLDialect 等)
<prop?key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
ddl配置:
<prop?key="hibernate.hdm2ddl.auto">update</prop>
目前的問題是不能自動建表,數(shù)據(jù)庫已經(jīng)創(chuàng)建過了。調用dao方法,不能自動建表,導致保存數(shù)據(jù)錯誤:
HTTP?Status?500?-?could?not?insert:?[cn.muke.ssh.domain.Product];?SQL?[insert?into?product?(pname,?price)?values?(?,??)];?nested?exception?is?org.hibernate.exception.SQLGrammarException:?could?not?insert:?[cn.muke.ssh.domain.Product]
具體原因(部分):
root cause
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'ssh.product' doesn't exist
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
如果把表建好,執(zhí)行dao的相關操作,沒有問題。?
2017-02-15
找到問題了吧?<prop?key="hibernate.hdm2ddl.auto">update</prop>
寫錯了?<prop?key="hibernate.hbm2ddl.auto">update</prop>