配置Hibernate出现的各种坑

1.java.lang.ClassNotFoundException: javax.xml.bind.JAXBException

故障原因:

JAXB API是java EE 的API,因此在java SE 9.0 中不再包含这个 Jar 包。
java 9 中引入了模块的概念,默认情况下,Java SE中将不再包含java EE 的Jar包
而在 java 6/7 / 8 时关于这个API 都是捆绑在一起的

解决方案一:

降低JDK 9 版本到 JDK 6/7/8

解决方案二:(亲测可行)

手动加入这些依赖Jar包

要解决这个问题,我导入了下面这四个Jar包修复成功。

javax.activation-1.2.0.jar
http://search.maven.org/remotecontent?filepath=com/sun/activation/javax.activation/1.2.0/javax.activation-1.2.0.jar

jaxb-api-2.3.0.jar
http://search.maven.org/remotecontent?filepath=javax/xml/bind/jaxb-api/2.3.0/jaxb-api-2.3.0.jar

jaxb-core-2.3.0.jar
http://search.maven.org/remotecontent?filepath=com/sun/xml/bind/jaxb-core/2.3.0/jaxb-core-2.3.0.jar

jaxb-impl-2.3.0.jar
http://search.maven.org/remotecontent?filepath=com/sun/xml/bind/jaxb-impl/2.3.0/jaxb-impl-2.3.0.jar

下载上面这些文件和复制他们到libs文件夹下,
添加他们导入到Build Path中
重新运行即可

2.ERROR: HHH000346: Error during managed flush [org.hibernate.exception.ConstraintViolationException: could not execute statement]

原因:因为主键传递的时候传了一个空的字符串而不是null,所以无法进行新增。
解决办法:自己录入主键值

3.org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleT

我的错误是没有导入相应的jar包,jar包下载地址:
http://www.java2s.com/Code/Jar/j/Downloadjavassist3170gajar.htm
其他可能错误参考链接:
问题3:https://blog.csdn.net/liuzhengyang1/article/details/23127629

参考链接:
问题1:https://blog.csdn.net/jinchunzhao123/article/details/82695556
问题2:https://blog.csdn.net/hadues/article/details/79188793
详细代码参考链接:https://www.jb51.net/article/115756.htm

猜你喜欢

转载自blog.csdn.net/weixin_42542536/article/details/91427708