hibernate小白bug

hibernate基础学习1
hibernate基础学习2
hibernate基础学习3
增删查改小实例1
增删查改小实例2

前几天刚开始用hibernate框架与springMVC框架联合起来,遇到了几个连接数据库的小bug,记录一下:

  1. Could not locate cfg.xml resource [hibernate.cfg.xml]
    需要把hibernate.cfg.xml文件放在src文件夹下,或者在指定的resource文件夹下
  2. org.hibernate.MappingNotFoundException: resource:**.hbm.xml not found
    一开始以为是mapping映射resource写错了,搞了很久
    解决办法
  3. Unable to create requested service
    纯属自己没有完全理解hibernate框架的整个运行流程,在hibernate.cfg.xml配置文件中没有写入用户名、密码、方言
 <!-- 第一部分: 配置数据库信息 必须的 -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
//数据库是zz2017,问号后面的是设置一下字符编码,我防止数据库中文字符乱码问题
<property name="hibernate.connection.url">jdbc:mysql:///zz2017?useUnicode=true&amp;characterEncoding=UTF8</property>
<property name="hibernate.connection.username">root</property>
//我数据库密码为空,故不写
<property name="hibernate.connection.password"></property>

猜你喜欢

转载自blog.csdn.net/qq_40738827/article/details/88806246
bug