Hibernate实现时的错误

1.字符集问题:

  Error logon to database using mysql driver: unknown initial character set index "255" was received from server.

  The initial client character set can be forced through the character encoding property.

解决办法:

  给它字符集

  在数据库名后加?useUnicode=true&characterEncoding=gb2312

  例如 :jdbc:mysql://localhost:3306/world?useUnicode=true&characterEncoding=gb2312

 

2.xml报错问题:

  The reference to entity "characterEncoding" must end with the ';' delimiter.

解决办法:

  使用转义字符,将&用转义字符替代

  转义字符:     

  &lt;      <    小于号 

  &gt;       >      大于号 

  &amp;    &    and字符

  &apos;    '     单引号 

  &quot;    "     双引号

 

3.无法访问xml问题:

  Unable to read XML

  http://hibernate.org/dtd/hibernate-mapping-3.0.dtd%20 Nested exception: http://hibernate.org/dtd/hibernate-mapping-3.0.dtd%20

解决办法:

  hibernate在生成hbm.xml文件时有可能会在

  <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"

  "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

  的dtd后多一个空格,只需把这个空格删掉即可

 

4.应用BeanValidation关系约束时出错:

  Error applying BeanValidation relational constraints

  Unable to build the default ValidatorFactory

  Unable to instantiate Configuration.

解决措施:

  javax.persistence.validation.mode默认情况下是auto的,就是说如果不设置的话它是会自动去你的classpath下面找一个bean-validation**包,但是找不到,所以beanvalitionFactory错误  

  在hibernate.hbm.xml中加上<property name="javax.persistence.validation.mode">none</property>


5.数据库不返回本机生成的标识值问题:

  The database returned no natively generated identity value

解决方法:

  在设置生成器(<generator class=" " />)的时候使用native则数据库主键设为要自动增加

  设置方法:https://www.cnblogs.com/liangcheng11/p/6380922.html

字符集参考:https://bbs.csdn.net/topics/100091366
关系约束参考:https://blog.csdn.net/sivyer123/article/details/9185325

 

 

posted @ 2018-12-10 19:11  市井小民665  阅读(163)  评论(0)    收藏  举报