hibernate 入门(3)
如果大家有什么不清楚的,可以下载这篇文章的例子看看,运行一下。
下载地址:点击下载
下载完以后用jb打开hibernate.jpx就可以了。用之前把hibernate和mysql的驱动加进去,方法如果不知道再看看本章开头部分。
常见错误:
caused by: org.dom4j.documentexception: invalid byte 2 of 2-byte utf-8 sequence. nested exception: invalid byte 2 of 2-byte utf-8 sequence.
如果出现这行错误说明你的xml配置文件有不规范的字符,检查下。
net.sf.hibernate.mappingexception: error reading resource: hibernate/hello_bean.hbm.xml
如果出现这行错误说明你的hibernate的xml配置文件有错
net.sf.hibernate.mappingexception: resource: hibernate/hello_bean.hbm.xml not found
如果出现这行错误说明hibernate的xml配置文件没有找到,你应该把xml文件放在与你的类文件同个目录下,本文中是放在hibernate/classes/hibernate/目录下,也就是跟hello_bean.class类文件一起。
net.sf.hibernate.propertynotfoundexception: could not find a setter for property name in class hibernate.hello_bean
如果出现这行错误说明你的xml文件里设置的字段名name的值与hello_bean.java类里的getxxx或setxxx方法不一致。
net.sf.hibernate.hibernateexception: jdbc driver class not found: org.gjt.mm.mysql.driver
如果出现这行错误说明你的mysql驱动没有加进jb库里或者不在classpath里。(全文完)
闽公网安备 35060202000074号