小序
或许网上搜罗下就能得到相关异常得解决方案了,个人相信这之后再遇到类似的异常,定会走同样的路。既然如此,何不深刻的理解下并记录下来,即使只是一些简单的问题也好。[不积跬步无以成千里]
异常记录
org.hibernate.AnnotationException: No identifier specified for entity: Student
- 对象关系映射的未加上主键 @Id
- hibernate.cfg.xml 配置文件中未添加对 Student 对象的 < mapping > 标签声明
org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned beforeQuery calling save():Student
- “assigned”指示对象当中的主键未分配相应的属性值,这里我给 int 类型的主键加上自增注解 @GeneratedValue
org.hibernate.exception.SQLGrammarException: error performing isolated work
- hibernate.cfg.xml 配置文件中添加< property name=”hibernate.hbm2ddl.auto” >validate< /property >
No default (no-argument) constructor for class: Student (class must be instantiated by Interceptor)
- Student 对象须实现不带参数的默认构造函数,不然无法完成 hibernate 数据映射
check the manual that corresponds to your MySQL server version for the rightonds to your MySQL server version for the right syntax to use near ‘type=MyISAM’ at line 7
- MySQL 版本兼容问题,方言< property name=”dialect”>设置为如下:
- org.hibernate.dialect.MySQLInnoDBDialect(mysql5.0以前使用)
- org.hibernate.dialect.MySQL5InnoDBDialect(mysq5.1-5.5)
- org.hibernate.dialect.MySQLDialect(这个试了好像没用)
org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.component.PojoComponentTuplizer]
…
org.hibernate.PropertyNotFoundException: Could not locate getter method for property [Address#mPostcode]
- 如异常内容提示可知,是属性映射 getter 对应属性出错。后发现是属性命名与 getter/setter 存在命名问题,如经设置“mPostcode”这个属性在生成 getter/setter 后为 getPostcode(),其正确写法应该是 getmPostcode()。很奇怪这种情况对普通类型的属性并没有影响,这里是组合属性映射出现的问题。
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
- 需要将对应的 mysql-connector-java-*-bin.jar 包放置 Tomcat 的 lib 目录下
- 另外还要将该文件名配置于 jre 的 CLASS_PATH 路径下