Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister

版权声明:原创文章欢迎转载,不过要记得加出处哦 https://blog.csdn.net/wljk506/article/details/85207672

错误描述:
spring boot 启动时报错
javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister

环境pox.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.7.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>admin-data</artifactId>
    <properties>
        <java.version>11</java.version>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <javax.persistence-api.version>2.2</javax.persistence-api.version>
        <javax.servlet-api.version>4.0.1</javax.servlet-api.version>
        <commons-lang3.version>3.8.1</commons-lang3.version>
        <disruptor.version>3.3.7</disruptor.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven-install-plugin.version>2.5.2</maven-install-plugin.version>
        <lombok.version>1.18.2</lombok.version>
        <redis-lettuce.version>4.5.0.Final</redis-lettuce.version>
        <commons-pool2.version>2.6.0</commons-pool2.version>
        <fastjson.version>1.2.51</fastjson.version>
        <druid.version>1.1.12</druid.version>
        <druid-spring-boot-starter.version>1.1.10</druid-spring-boot-starter.version>
        <log-slf4j.version>1.7.25</log-slf4j.version>
        <!-- mysql驱动版本号 -->
        <!--<mysql-driver.version>5.1.47</mysql-driver.version>-->
        <mysql-driver.version>8.0.13</mysql-driver.version>
        <!-- charset encding -->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>
    <dependencies>
        <!-- start: spring boot -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!-- spring-data-jpa -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <!-- 数据库 -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <!--<scope>runtime</scope>-->
            <version>${mysql-driver.version}</version>
        </dependency>
        <!-- spring-security 和 jwt -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt</artifactId>
            <version>0.9.1</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.glassfish.jaxb/jaxb-core -->
        <dependency>
            <groupId>org.glassfish.jaxb</groupId>
            <artifactId>jaxb-core</artifactId>
            <version>2.3.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${log-slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${lombok.version}</version>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>${commons-lang3.version}</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>1.9.13</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.6</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.54</version>
        </dependency>
    </dependencies>
</project>

foxwho.风
解决方法:增加依赖

<dependency>
            <groupId>org.javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.23.1-GA</version>
        </dependency>

解决问题的思路:
把springboot<artifactId>spring-boot-starter-parent</artifactId>版本升级到最新版2.1.1.RELEASE,可以解决报错问题。
但是 项目都是基于2.0.7.RELEASE 版本的,升级到最新版,其他模块都报错,所以只能在此基础上进行解决。

搜索了网络的各种方法,都没用,最后实在没有办法了。把内部依赖一个个升级试试看。
最后升级到此处javassist时才完美解决启动报错。

org.hibernate.MappingException: Could not get constructor for org.hibernate.pers

10-23

org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersisterrn at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:185)rn at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:135)rn at org.hibernate.internal.SessionFactoryImpl.(SessionFactoryImpl.java:401)rn at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1859)rn at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1930)rn at cn.ntt.domain.App.SchemaExpore(App.java:16)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:597)rn at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)rn at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)rn at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)rn at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)rn at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)rn at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)rn at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)rn at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)rn at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)rn at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)rn at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)rn at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)rn at org.junit.runners.ParentRunner.run(ParentRunner.java:236)rn at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)rn at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)rnCaused by: org.hibernate.PropertyAccessException: Exception occurred inside getter of cn.ntt.domain.User.idrn at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:172)rn at org.hibernate.engine.internal.UnsavedValueFactory.getUnsavedIdentifierValue(UnsavedValueFactory.java:85)rn at org.hibernate.tuple.PropertyFactory.buildIdentifierAttribute(PropertyFactory.java:87)rn at org.hibernate.tuple.entity.EntityMetamodel.(EntityMetamodel.java:163)rn at org.hibernate.persister.entity.AbstractEntityPersister.(AbstractEntityPersister.java:520)rn at org.hibernate.persister.entity.SingleTableEntityPersister.(SingleTableEntityPersister.java:148)rn at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)rn at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)rn at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)rn at java.lang.reflect.Constructor.newInstance(Constructor.java:513)rn at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:163)rn ... 28 morernCaused by: java.lang.reflect.InvocationTargetExceptionrn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:597)rn at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:169)rn ... 38 morernCaused by: java.lang.NullPointerExceptionrn at cn.ntt.domain.User.getId(User.java:7)rn ... 43 morernrnrn配置hibernate.cfg.xmlrn rn com.mysql.jdbc.Driverrn jdbc:mysql:///hibernate_1022rn rootrn 123rn rn org.hibernate.dialect.MySQL5InnoDBDialectrn rn updatern truern rn rn rn rnrnrn配置User.hbm.xmlrnrnrn rn rn rn rn rn rnrnrn

大神请进org.hibernate.MappingException: Could not get constructor for org.hibernate

09-11

org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersisterrn 怎么回事啊。。。rnrnrnrn源码如下:rnrnpackage entity;rnrnimport javax.imageio.spi.ServiceRegistry;rnrnimport org.hibernate.Session;rnimport org.hibernate.SessionFactory;rnimport org.hibernate.boot.registry.StandardServiceRegistry;rnimport org.hibernate.boot.registry.StandardServiceRegistryBuilder;rnimport org.hibernate.cfg.Configuration;rnimport org.hibernate.tool.hbm2ddl.SchemaExport;rnimport org.junit.Test;rnrnpublic class testStudent rnrn @Testrn public void SchemaExpore() rn Configuration config = new Configuration().configure();rn StandardServiceRegistryBuilder standardServiceRegistryBuilder = new StandardServiceRegistryBuilder().applySettings(config.getProperties());rn StandardServiceRegistry standardServiceRegistry = standardServiceRegistryBuilder.build();rn SessionFactory sessionFactory = config.buildSessionFactory(standardServiceRegistry);rn SchemaExport export = new SchemaExport(config);rn export.create(true, true);rn rnrnrnrn我不加StandardServiceRegistryBuilder standardServiceRegistryBuilder = new StandardServiceRegistryBuilder().applySettings(config.getProperties());rn StandardServiceRegistry standardServiceRegistry = standardServiceRegistryBuilder.build();rn SessionFactory sessionFactory = config.buildSessionFactory(standardServiceRegistry);rn的时候没事,,但加了就报这个错了,,求大神rn

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试