1、今天弄了一下Hibernate,根据文档进行配置,运行的时候出现了这个错误org.hibernate.exception.SQLGrammarException: could not insert: 。
开始以为是配置文件错,反反复复把配置文件查了好多遍,后来发现是映射对象的id类型导致的,一但带向id类型为String就会有这个错误,当把ID改为int类型问题就解决了,(同理long也应该是可以的)
2、在检索的时候使用session.get(Class,Serializable)这个方法根据ID查询,我的对象定义的id是long型,当我使用这个方法,传入的id是int型时,报这个类型不匹配错误org.hibernate.TypeMismatchException: Provided id of the wrong type. Expected: class java.lang.Long, got class java.lang.Integer,只要在使用这个get方法的时候,id类型转换为Class这个类的id类型即可。
3、can‘t insert 因为配置文件中表别名写成了user-table,mysql的表名不识别”-“这个符号,改掉后OK
4、Could not parse mapping document from resource domain/Department.hbm.xml ,在排除jar包错误之后,检查这个配置文件