hibernate创建sessionFactory时抛出异常,求助大神们

在本地计算机上是运行正常的,然而我部署在阿里云服务器上面之后,却运行失败,找不到问题。

崩溃的代码块:

        final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
                .configure()
                .build();
        // build 一个sessionFactory
        SessionFactory sessionFactory = new MetadataSources(registry)
                .buildMetadata()
                .buildSessionFactory();

抛出的异常:

javax.servlet.ServletException: org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister
    org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:434)
    org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:372)
    org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:389)
    org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:342)
    org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:229)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause

org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister
    org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:123)
    org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:77)
    org.hibernate.metamodel.internal.MetamodelImpl.initialize(MetamodelImpl.java:181)
    org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:294)
    org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:462)
    org.hibernate.boot.internal.MetadataImpl.buildSessionFactory(MetadataImpl.java:184)
    com.pyn.web.welearn.factory.UserFactory.login(UserFactory.java:62)
    com.pyn.web.welearn.service.AccountService.login(AccountService.java:31)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:498)
    org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda$static$0(ResourceMethodInvocationHandlerFactory.java:74)
    org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:144)
    org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161)
    org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:247)
    org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99)
    org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:388)
    org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:346)
    org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102)
    org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:337)
    org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
    org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
    org.glassfish.jersey.internal.Errors.process(Errors.java:315)
    org.glassfish.jersey.internal.Errors.process(Errors.java:297)
    org.glassfish.jersey.internal.Errors.process(Errors.java:267)
    org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:280)
    org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:316)
    org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1084)
    org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:418)
    org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:372)
    org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:389)
    org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:342)
    org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:229)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause

org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]
    org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:91)
    org.hibernate.tuple.entity.EntityTuplizerFactory.constructDefaultTuplizer(EntityTuplizerFactory.java:116)
    org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:382)
    org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:556)
    org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:124)
    sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:96)
    org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:77)
    org.hibernate.metamodel.internal.MetamodelImpl.initialize(MetamodelImpl.java:181)
    org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:294)
    org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:462)
    org.hibernate.boot.internal.MetadataImpl.buildSessionFactory(MetadataImpl.java:184)
    com.pyn.web.welearn.factory.UserFactory.login(UserFactory.java:62)
    com.pyn.web.welearn.service.AccountService.login(AccountService.java:31)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:498)
    org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda$static$0(ResourceMethodInvocationHandlerFactory.java:74)
    org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:144)
    org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161)
    org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:247)
    org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99)
    org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:388)
    org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:346)
    org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102)
    org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:337)
    org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
    org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
    org.glassfish.jersey.internal.Errors.process(Errors.java:315)
    org.glassfish.jersey.internal.Errors.process(Errors.java:297)
    org.glassfish.jersey.internal.Errors.process(Errors.java:267)
    org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:280)
    org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:316)
    org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1084)
    org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:418)
    org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:372)
    org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:389)
    org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:342)
    org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:229)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

3个回答

javax.servlet.ServletException: org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister

找不到这个类的构造器:SingleTableEntityPersister
你本地可以应该说明你本地可以找到,服务器上面不行就是服务器依赖和本地不同,如果你是用的maven把本地的hibernate上传到服务器的仓库试试,不过也未必是hibernate的问题,可能是jdk版本等问题,需要逐一排查.

如果你是本地打包上传服务器的话那就不用考虑依赖了..
jdk相关的环境要一致,还有服务器 (比如tomcat)要一个版本

weixin_39708641
求导布道 几经折腾,终于把问题解决了,我原本是通过idea自动上传部署到云服务器的,这需要修改服务器tomcat/bin目录下的catalina.sh配置文件,可能是某些冲突,导致了运行不成功。于是我尝试着换一个新的tomcat,不修改catalina.sh文件,而是手动打包上传,结果运行成功了
5 个月之前 回复
weixin_39708641
求导布道 但我的实体是使用注解映射的,链接中是另外一种映射,需要修改后才能尝试
5 个月之前 回复

org.hibernate.tuple.entity.PojoEntityTuplizer 可以看下是否是这个实体类配置问题。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!