转自: http://blog.csdn.net/biangren/article/details/8010018

最近开始学Hibernate,看的是李刚的那本《轻量级java ee企业应用实战》。头一个hibernate程序,我原原本本的按照书上例子写下来,同时只是改动了些mysql的连接参数,并且在mysql中新建了一个hibernate数据库,仅此而已。然而预想不到的事情发生了……程序写好之后,运行,报错

Hibernate: insert into news_table (title, content) values (?, ?)
       Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not insert: [org.crazyit.app.domain.News]

…………此处省略
      Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'hibernate.news_table' doesn't exist

…………此处省略

当时我就蛋疼了……情况是这样的,如果在mysql中把news_table表建好,然后运行成功,这说明连接肯定是没问题的。可就是不能自动建表,百度啊,遇到同样问题的人不少,按照他们所说的一个个去解决,可是还是没有效果。csdn上也发帖问了,有人说是:  <propertyname="hibernate.hbm2ddl.auto">update(create)</property>这个设置有问题,应该用update。好吧,我敢说我本来用的就是update,还是会出错。。有人说是什么mysql引擎不配对的缘故,好吧,我敢说<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>这样设置,在mysql的配置文件ini中什么引擎之类的也是innodb的(这个不太了解,随便说点),当时我想问题肯定也不在这。还有人说,可能是你持久类的字段设置成为关键字,这个更不靠谱了。。。。。

后来我想也许是版本兼容问题,书上说的是用Hibernate3我用的是hibernate4。好吧我就重新下载hibernate3还是没用。。。。。。就这样,两天下来,什么各种方式都尝试了,还是报一样错

最后实在没法了,看了下hibernate的视频教程,一步一步跟着做,每一个细节都不放过,尝试着hibernate.cfg.xml和**.hbm.xml的每一个配置。。。。。终于才被我发现了

原来的配置如下:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
  <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
  <property name="hibernate.connection.password">liaobin1992</property>
  <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/hibernate</property>
  <property name="hibernate.connection.username">root</property>
  <property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
  <property name="hibernate.show_sql">true</property>
  <property name="hibernate.hbm2ddl.auto">update</property>
  <mapping resource="org/crazyit/app/domain/News.hbm.xml"/>       
</session-factory>
</hibernate-configuration>
更改之后的配置:

<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
把这行换成:

<property name="hibernate.dialect">org.hibernate.dialect.MySQDialect</property>

这样就行了 ,然后整个世界都安静了。。

虽然没明白为什么这么做,但是终于解决了问题,还是有点点的欣慰。。。

哪位大侠路过能帮忙解释下 ,这是为什么?

[转] Hibernate不能自动建表解决办法(hibernate.hbm2ddl.auto) (tables doesn't exist)的更多相关文章

  1. Hibernate不能自动建表解决办法

    最近开始学Hibernate,看的是李刚的那本<轻量级java ee企业应用实战>.头一个hibernate程序,我原原本本的按照书上例子写下来,同时只是改动了些mysql的连接参数,并且 ...

  2. [转]Hibernate不能自动建表解决办法及Hibernate不同数据库的连接及SQL方言

    最近开始学Hibernate,看的是李刚的那本<轻量级java ee企业应用实战>.头一个hibernate程序,我原原本本的按照书上例子写下来,同时只是改动了些mysql的连接参数,并且 ...

  3. hibernate注解(自动建表如何有表DDL注释) -- Comment用法

    import java.io.Serializable; import java.sql.Date; import java.sql.Timestamp; import javax.persisten ...

  4. 配置hibernate根据实体类自动建表功能

    Hibernate支持自动建表,在开发阶段很方便,可以保证hbm与数据库表结构的自动同步. 如何使用呢?很简单,只要在hibernate.cfg.xml里加上如下代码 Xml代码<propert ...

  5. Hibernate+maven+eclipse 实现自动建表

    一.需求 如题,当建好Model 时,不想自己手工建表,可以采取hibernate进行自动建表.下面将用一个小例子来说明如何将其实现. 二.实现 说明:1)这里用的是4.3.1.Final版本的hib ...

  6. 第三次 orm自动建表及遇到的问题

    Hibernate支持自动建表,在开发阶段很方便,可以保证hbm与数据库表结构的自动同步. 方法很简单,在hibernate.cfg.xml内加入 <property name="hi ...

  7. Hibernate不能自动建数据表解决办法

    首先自己要注意自己的MYSQL版本,然后设置对应的方言 兼容性模式 <property name="hibernate.dialect">org.hibernate.d ...

  8. Activiti+oracle 启动项目时不能自动建表或更新表的问题分析及解决办法

    现象描述:按照正常配置,第一次启动时不能自动建表 关键配置片段如下: <bean id="processEngineConfiguration" class="or ...

  9. hibernate自动建表采用UTF-8字符编码

    hibernate自动建表采用UTF-8字符编码 hibernate建表默认为UTF-8编码 >>>>>>>>>>>>>& ...

随机推荐

  1. 【leetcode】Balanced Binary Tree

    Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary ...

  2. Vue mixins extends extend components

    mixins 调用方式: mixins: [mixin1, mixin2] 是对父组件的扩充,包括methods.components.directive等... 触发钩子函数时,先调用mixins的 ...

  3. 使用Pydoc生成文档

    Python中本身带有很多实用的工具,如pydoc.pydoc模块主要用来从Python模块中提取信息并生成文档. 使用方法 在Windows和Linux下的使用方法有些区别. Windows pyt ...

  4. Node教程

    本人的博客写了node的教程,从零开始,一步一步的通过例子讲解,希望喜欢的同学给我的github上加颗星,谢谢! github地址:https://github.com/manlili/node_le ...

  5. Hadoop切换namenode为active

    hadoop切换namenode为active 进入hadoop/bin目录下 ./yarn rmadmin -transitionToActive --forcemanual rm1 重新启动zkf ...

  6. bzoj 1699: [Usaco2007 Jan]Balanced Lineup排队 分块

    1699: [Usaco2007 Jan]Balanced Lineup排队 Time Limit: 5 Sec  Memory Limit: 64 MB Description 每天,农夫 John ...

  7. codeforces 707B B. Bakery(水题)

    题目链接: B. Bakery 题意: 是否存在一条连接特殊和不特殊的边,存在最小值是多少; 思路: 扫一遍所有边: AC代码: #include <iostream> #include ...

  8. flex 和bison的安装和使用

    1.在ubutu上安装 yacc的命令: sudo apt-get install flex bison flex:词法分析器 flex是一个词法分析器.用来将一个.l文件生成一个.c程序文件.即生成 ...

  9. FJOI2016 神秘数

    题目大意 给定长为$N$一个序列,每次询问一个区间,求最小的不能表示为由区间内若干个(可以是$0$个)数的和的非负整数. 考虑一个可重集合$S$,设抽取$S$中若干个数相加无法得到的最小非负整数为$A ...

  10. bzoj 1833: [ZJOI2010]count 数位dp

    题目: 给定两个正整数a和b,求在[a,b]中的所有整数中,每个数码(digit)各出现了多少次. 题解 设\(f[i][j]\)表示长度为\(i\)的所有合法数字中有多少数码\(j\) 设\(g[i ...