报错Could not get constructor for org.hibernate.persister.entity...

来源:11-5 -Spring Security 实战-前台编码

Pinkcoix

2019-01-22

详细报错信息如下:org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘entityManagerFactory’ defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is 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
上网查阅相关资料都说是实体类没有实现映射,可能是缺少setter getter或是不规范之类,但是我的代码完全按照老师来的,下面是User实体类的代码:

package com.sherry.springboot.blog.domain;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity // 实体
public class User {

    @Id // 主键
    @GeneratedValue(strategy=GenerationType.IDENTITY) // 自增策略
    private Long id; // 实体一个唯一标识
    private String name;
    private String email;

    protected User() { // 无参构造函数;设为 protected 防止直接使用
    }

    public User(Long id, String name, String email) {
        this.id = id;
        this.name = name;
        this.email = email;
    }

    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }

    @Override
    public String toString() {
        return String.format("User[id=%d,name='%s',email='%s']", id, name, email);
    }
}
请问问题是出在哪里呢?

写回答

1回答

老卫

2019-01-22

Hibernate 的配置有问题吧~

0
2
Pinkcoix
你好,我找到问题所在了,是java版本过高了.
2019-01-23
共2条回复

基于Spring Boot技术栈博客系统企业级前后端实战

毕设 Elasticsearch搜索+Thymeleaf模板+JPA+Security+BootStrap

1296 学习 · 738 问题

查看课程