初次使用Hibernate遇到的问题整理

这里记载的是本人(新手)遇到的问题,仅供个人参考。

在:http://how2j.cn/k/hibernate/hibernate-tutorial/31.html

初次接触学习Hibernate

学习工具:

IntelliJ IDEA2018.1.6

MySQL5.7.22

Hibernate架包:

初次使用Hibernate遇到的问题整理

1.com.mysql.jdbc.exceptions.MySQLSyntaxErrorException

初次使用Hibernate遇到的问题整理

大概SQL语法错误。这个需要事先在product表增加cid字段(int),

初次使用Hibernate遇到的问题整理

新建一个user_product表(uid,pid)

Hibernate中有个配置:<property name="hbm2ddl.auto">update</property>
这表示是否会自动更新数据库的表结构,有这句话,其实是不需要创建表的,因为Hibernate会自动去创建表结构

查询得到的新表要事先建立好,有新的字段就添加,上面那个配置也许是版本原因吧,不生效。

2.java.lang.NullPointerException

初次使用Hibernate遇到的问题整理

空异常。要查找的id(category表)不存在。低级错误啊!

3.org.hibernate.MappingException:Repeated column in mapping for collection

初次使用Hibernate遇到的问题整理

集合映射中的重复列。一定要到xxx.hbm.xml配置文件中看映射哪里不对。