Hibernate 在 EntityTuplizerFactory.constructTuplizer 中失败并出现 NullPointerException?为什么?
当我尝试实例化 Hibernate 并连接 MySQL 数据库时遇到问题(请参阅下面的错误消息)。
奇怪的是,在运行 Junit 测试时,使用完全相同的 hibernate.cfg.xml 文件连接工作正常,但在从 Tomcat 运行时却无法工作......
我开始没有想法了。
有什么线索或提示去哪里寻找吗?
原因:org.hibernate.HibernateException:无法实例化默认 tuplizer [org.hibernate.tuple.entity.DynamicMapEntityTuplizer] 在org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:110) 在org.hibernate.tuple.entity.EntityTuplizerFactory.constructDefaultTuplizer(EntityTuplizerFactory.java:135) 在 org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.(EntityEntityModeToTuplizerMapping.java:69) 在 org.hibernate.tuple.entity.EntityMetamodel.(EntityMetamodel.java:323) 在 org.hibernate.persister.entity.AbstractEntityPersister。(AbstractEntityPersister.java:456) 在 org.hibernate.persister.entity.SingleTableEntityPersister。(SingleTableEntityPersister.java:131) 在 org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:84) 在 org.hibernate.impl.SessionFactoryImpl.(SessionFactoryImpl.java:267) 在 org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1341) 在se.fmt.atlantism.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:16) ... 38 更多 引起原因:java.lang.NullPointerException 在org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:107) ... 47 更多
I have a problem when I try to instantiate Hibernate and connect with a MySQL database (see error message below).
Curiously enough the connection works fine using the exact same hibernate.cfg.xml file when running Junit tests but it refuses to work when run from Tomcat...
I am starting to run out of ideas.
Any clues or tip where to look?
Caused by: org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.DynamicMapEntityTuplizer]
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:110)
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructDefaultTuplizer(EntityTuplizerFactory.java:135)
at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.(EntityEntityModeToTuplizerMapping.java:69)
at org.hibernate.tuple.entity.EntityMetamodel.(EntityMetamodel.java:323)
at org.hibernate.persister.entity.AbstractEntityPersister.(AbstractEntityPersister.java:456)
at org.hibernate.persister.entity.SingleTableEntityPersister.(SingleTableEntityPersister.java:131)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:84)
at org.hibernate.impl.SessionFactoryImpl.(SessionFactoryImpl.java:267)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1341)
at se.fmt.atlantism.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:16)
... 38 more
Caused by: java.lang.NullPointerException
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:107)
... 47 more
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我写这篇文章是为了供未来的 Google 员工参考。
我做了更多研究,但问题的根源仍然未知。然而,下面的文章让我走上了正轨。
http://www.howtogeek.com/howto/linux /installing-tomcat-6-on-ubuntu/
Ubuntu(和 Debian)中可用的 Tomcat(至少版本 6)软件包似乎无法正常工作。相反,我使用以下指南安装了 Tomcat:
http://www.ctrip.ufl .edu/tomcat6-debian-lenny-howto
虽然这可能不是最佳安装选择,但似乎有必要让 Tomcat 版本 6 在 Ubuntu 和/或 Debian Lenny 上顺利运行。
I'm writing this for future Googlers and reference.
I've done some more research and the root source of the problem is still not known. However the following article throw me on the right track.
http://www.howtogeek.com/howto/linux/installing-tomcat-6-on-ubuntu/
It seems like the Tomcat (version 6 at least) packages available in Ubuntu (and Debian) are not working correctly. Instead I installed Tomcat using the following guide:
http://www.ctrip.ufl.edu/tomcat6-debian-lenny-howto
While this might not be the premium choice of installation it seems necessary to get Tomcat version 6 running without problems on Ubuntu and/or Debian Lenny.
就我而言,这个错误是通过切换> 来解决的。在我的 pom.xml 中订购。当 hibernate (3.2.7.ga) 在 hibernate-annotations (3.4.0.GA) 之前出现时,会发生此错误。反过来说,它工作得很好。即使使用scope=compile 也是如此。
我猜你需要调整你的类路径,除了(假设你已经将两个 jar 放在 WEB-INF/lib 中)它应该以正确的顺序进行 alpha 排序。但这也许会给某人带来如何前进的提示。
In my case, this error was resolved by switching the <dependency/> order in my pom.xml. When hibernate (3.2.7.ga) comes before hibernate-annotations (3.4.0.GA) this error occurs. The other way around, it works fine. This is the case even with scope=compile.
I would guess that you need to tweak your classpath, except that (assuming you've dropped both jars in WEB-INF/lib) it should alpha-sort in the correct order. But maybe this will give someone a hint on how to move forward.
就我而言,这是一个简单的错误 - 配置文件 *.hbm.xml 有一个映射对象没有的属性!我还听说过当你拼错 get/set 函数时出现该错误的情况 - 与我的情况非常相似。
In my case it was a simple mistake - the config file *.hbm.xml had a property that the mapped object didnt have! I also heard of cases of that error apearing when you misspell a get/set function - very similar to my case.
我面临着同样的问题。我下载“javassist.jar”并将其放入类路径后它就消失了: http://www.java2s.com/Code/Jar/JKL/Downloadjavassistjar.htm
I was facing the same problem. It went away after I downloaded "javassist.jar" and put it in the classpath: http://www.java2s.com/Code/Jar/JKL/Downloadjavassistjar.htm
这是 Tomcat 守护进程进程的外观:
这是使用 Sysdeo Tomcat 启动器插件从 Eclipse 中运行时 Tomcat 进程的外观:
(这个实际上有效)
工作的(Eclipse启动)是使用java-6-sun-1.6.0.15运行的,我是Windows用户,所以我不知道如何判断/usr/lib/使用哪个JRE jsvc(虽然看着它),但我猜它是一些 OpenJDK...这可能是区别吗?
更新:jsvc 可能使用相同的 JRE Sysdeo Tomcat 启动器
This is how the Tomcat daemon process looks:
This is how the Tomcat process looks when run from within Eclipse using the Sysdeo Tomcat launcher plugin:
(this one actually works)
The working one (Eclipse launched) is run using java-6-sun-1.6.0.15, I'm Windows user so I don't know how to tell which JRE is used for /usr/lib/jsvc (looking at it though), but my guess would be it is some OpenJDK... Could this be the difference?
update: jsvc probably uses the same JRE Sysdeo Tomcat launcher does