Hibernate不能自动建数据表解决办法
2016-12-19 00:14
337 查看
首先自己要注意自己的MYSQL版本,然后设置对应的方言
兼容性模式
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
需要注意的是5.5一下版本可以使用
<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
Mysql数据库版本是5.5的,设置事务性方言时要修改,就是加一个5
<property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
此外还要注意其他方面的问题
1.错误原因:hbm文件中定义的元素含有sql的关键字
例如: <property name="name"></property> <property name="birthday"></property> <property name="from"></property> 代码中含有"from"关键字.
2.错误原因:配置文件中使用了create-drop属性,数据库表其实已经创建,只是又被删除了:
<property name="hbm2ddl.auto">create-drop</property> 只要把create-drop替换为create即可
3.错误原因:默认的数据库类型错误。
把mysql中my.ini文件中配置的 MyISAM 变成 INNODB,代码如下:
# The default storage engine that will be used when create new tables when
default-storage-engine=INNODB
4.错误原因;hbm文件中未写错,但是在myeclipse中开发的
myeclipse不能自动识别如下语句,需要在Configuration中手动重新配置一下即可运行;
<property name="hbm2ddl.auto">update</property>
5.如果在spring里面集成hibernate3,
例如配置代码如下:
注意每行结尾没有空格,不然也会造成不能自动建表的后果
What a meaningless sense if losing myself,though owning all of the world.
兼容性模式
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
需要注意的是5.5一下版本可以使用
<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
Mysql数据库版本是5.5的,设置事务性方言时要修改,就是加一个5
<property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
此外还要注意其他方面的问题
1.错误原因:hbm文件中定义的元素含有sql的关键字
例如: <property name="name"></property> <property name="birthday"></property> <property name="from"></property> 代码中含有"from"关键字.
2.错误原因:配置文件中使用了create-drop属性,数据库表其实已经创建,只是又被删除了:
<property name="hbm2ddl.auto">create-drop</property> 只要把create-drop替换为create即可
3.错误原因:默认的数据库类型错误。
把mysql中my.ini文件中配置的 MyISAM 变成 INNODB,代码如下:
# The default storage engine that will be used when create new tables when
default-storage-engine=INNODB
4.错误原因;hbm文件中未写错,但是在myeclipse中开发的
myeclipse不能自动识别如下语句,需要在Configuration中手动重新配置一下即可运行;
<property name="hbm2ddl.auto">update</property>
5.如果在spring里面集成hibernate3,
例如配置代码如下:
<property name="hibernateProperties"> <value> hibernate.dialect=org.hibernate.dialect.MySQLDialect//注意这些地方没有空格 hibernate.hbm2ddl.auto=update//注意这些地方没有空格 hibernate.show_sql=false//注意这些地方没有空格 hibernate.format_sql=false//注意这些地方没有空格 </value> </property>
注意每行结尾没有空格,不然也会造成不能自动建表的后果
What a meaningless sense if losing myself,though owning all of the world.
相关文章推荐
- Hibernate不能自动建数据表解决办法
- Hibernate不能自动建表解决办法
- Hibernate不能自动建表解决办法
- 使用hibernate与mysql时数据不能插入的原因及解决办法
- Hibernate不能自动建表解决办法
- Hibernate3.x,hibernate3.x,Hibernate3.x整合Spring3.x不能实现自动创建表结构的解决办法:
- 转] Hibernate不能自动建表解决办法(hibernate.hbm2ddl.auto) (tables doesn't exist)
- Hibernate不能自动建表解决办法及Hibernate不同数据库的连接及SQL方言
- Hibernate不能自动建表解决办法
- Hibernate插入数据时自动清除以前数据的解决办法
- Hibernate不能自动建表解决办法【转载】
- Hibernate不能自动建表解决办法
- [转]Hibernate不能自动建表解决办法及Hibernate不同数据库的连接及SQL方言
- getHibernateTemplate().save();不能保存数据到数据库解决办法
- XP的系统防火墙不能用,自动更新显示灰色的解决办法
- 链接服务器不能更新和写数据的解决办法
- Linq2Sql数据实体外部更新时“不能添加其键已在使用中的实体”的解决办法
- hibernate先删除数据,紧接着执行插入时的异常解决之道——中间不能调用flush()、clear()等方法
- UTF-8在IE中不能自动选择编码的解决办法(utf8 网页在ie中自动编码乱码问题)
- "为自动填充列调整大小期间不能执行此操作"解决办法