求助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>
目前的问题是不能自动建表,数据库已经创建过了。调用dao方法,不能自动建表,导致保存数据错误:
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)
如果把表建好,执行dao的相关操作,没有问题。
找到问题了吧 <prop key="hibernate.hdm2ddl.auto">update</prop>
写错了 <prop key="hibernate.hbm2ddl.auto">update</prop>