嵌套异常是org.hibernate.MappingException:无法获取org.hibernate.persister.entity.SingleTableEntityPersister的构造函数

时间:2018-05-24 11:36:42

标签: java spring hibernate

我正在尝试将一些记录插入到一​​个名为LOG的表中但无法使用hibernate和spring启动应用程序,使用构建器模式生成对象LogBuilder类也包含在普通实体类中。请建议减少这个问题。

package com.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Entity
@Table(name = "LOG", catalog = "ADM")
public class HistoryLogEntity implements Serializable {
    private static final long serialVersionUID = 1L;

    private int objid;
    private String sessionId;
    private Date loggedinDate;

    private String browser;
    private String browserVersion;
    private String userId;

    private String action;
    private Date actionDate;
    private String context;

    private String subContext;
    private String operation;
    private int reference;

    private int subReference;
    private int refObjid;
    private int subRefObjid;

    private int programmId;
    private String masterTableRefrence;
    private String oldValue;

    private String newValue;
    private String reason;
    private String description;

    @Id
    @Column(name = "OBJID")
        public int getObjid() {
        return objid;
    }

    @Column(name = "SESSION_ID")
    public String getSessionId() {
        return sessionId;
    }

    @Column(name = "LOGGEDIN_DATE")
    public Date getLoggedinDate() {
        return loggedinDate;
    }

    @Column(name = "BROWSER")
    public String getBrowser() {
        return browser;
    }

    @Column(name = "BROWSER_VERSION")
    public String getBrowserVersion() {
        return browserVersion;
    }

    @Column(name = "USERID")
    public String getUserId() {
        return userId;
    }

    @Column(name = "ACTION")
    public String getAction() {
        return action;
    }

    @Column(name = "ACTION_DATE")
    public Date getActionDate() {
        return actionDate;
    }

    @Column(name = "CONTEXT")
    public String getContext() {
        return context;
    }

    @Column(name = "SUB_CONTEXT")
    public String getSubContext() {
        return subContext;
    }

    @Column(name = "OPERATION")
    public String getOperation() {
        return operation;
    }

    @Column(name = "REFERENCE")
    public int getReference() {
        return reference;
    }

    @Column(name = "SUB_REFERENCE")
    public int getSubReference() {
        return subReference;
    }

    @Column(name = "REF_OBJID")
    public int getRefObjid() {
        return refObjid;
    }

    @Column(name = "SUB_REF_OBJID")
    public int getSubRefObjid() {
        return subRefObjid;
    }

    @Column(name = "PROGRAMM_ID")
    public int getProgrammId() {
        return programmId;
    }

    @Column(name = "MASTER_TABLE_REFRENCE")
    public String getMasterTableRefrence() {
        return masterTableRefrence;
    }

    @Column(name = "OLD_VALUE")
    public String getOldValue() {
        return oldValue;
    }

    @Column(name = "NEW_VALUE")
    public String getNewValue() {
        return newValue;
    }

    @Column(name = "REASON")
    public String getReason() {
        return reason;
    }

    @Column(name = "DESCRIPTION")
    public String getDescription() {
        return description;
    }


    private HistoryLogEntity(LogBuilder builder) {
        this.sessionId = builder.sessionId;
        this.loggedinDate = builder.loggedinDate;
        this.browser = builder.browser;
        this.browserVersion = builder.browserVersion;
        this.userId = builder.userId;
        this.action = builder.action;
        this.actionDate = new Date();
        this.context = builder.context;
        this.subContext = builder.subContext;
        this.operation = builder.operation;
        this.reference = builder.reference;
        this.subReference = builder.subReference;
        this.refObjid = builder.refObjid;
        this.subRefObjid = builder.subRefObjid;
        this.programmId = builder.programmId;
        this.masterTableRefrence = builder.masterTableRefrence;
        this.oldValue = builder.oldValue;
        this.newValue = builder.newValue;
        this.reason = builder.reason;
        this.description = builder.description;
    }

    // LogBuilder class
    public static class LogBuilder {

        private String sessionId;
        private Date loggedinDate;
        private String browser;

        private String browserVersion;
        private String userId;
        private String action;

        private String context;
        private String subContext;
        private String operation;

        private int reference;
        private int subReference;
        private int refObjid;

        private int subRefObjid;
        public int programmId;
        public String masterTableRefrence;

        private String oldValue;
        private String newValue;
        private String reason;

        private String description;

        public LogBuilder(String sessionId, String userId, String action, String context, String operation) {
            this.sessionId = sessionId;
            this.userId = userId;
            this.context = context;
            this.action = action;
            this.operation = operation;
        }

        public LogBuilder loggedInTime(Date loggedInTime) {
            this.loggedinDate = loggedInTime;
            return this;
        }

        public LogBuilder browser(String browser) {
            this.browser = browser;
            return this;
        }

        public LogBuilder browserVersion(String browserVersion) {
            this.browserVersion = browserVersion;
            return this;
        }

        public LogBuilder subContext(String subContext) {
            this.subContext = subContext;
            return this;
        }

        public LogBuilder operation(String operation) {
            this.operation = operation;
            return this;
        }
        public LogBuilder refObjid(int refObjid) {
            this.refObjid = refObjid;
            return this;
        }
        public LogBuilder programmId(int programmId) {
            this.programmId = programmId;
            return this;
        }

        public LogBuilder masterTableRefrence(String masterTableRefrence) {
            this.masterTableRefrence = masterTableRefrence;
            return this;
        }

        public LogBuilder oldValue(String oldValue) {
            this.oldValue = oldValue;
            return this;
        }

        public LogBuilder newValue(String newValue) {
            this.newValue = newValue;
            return this;
        }

        public LogBuilder subRefObjid(int subRefObjid) {
            this.subRefObjid = subRefObjid;
            return this;
        }

        public LogBuilder subReference(int subReference) {
            this.subReference = subReference;
            return this;
        }

        public LogBuilder reason(String reason) {
            this.reason = reason;
            return this;
        }

        public LogBuilder description(String description) {
            this.description = description;
            return this;
        }

        public HistoryLogEntity build() {
            HistoryLogEntity historyLogEntity = new HistoryLogEntity(this);
            // validateHistoryLogEntityObject(historyLogEntity);
            return historyLogEntity;
        }

        private void validateHistoryLogEntityObject(HistoryLogEntity historyLogEntity) {
            // Do some basic validations to check
        }
    }
}

我从服务器日志获取的错误日志详细信息。

ERROR DispatcherServlet:502 - Context initialization failed
 Error creating bean with name 'XXXDaoImpl' defined in file [C:\Ajay\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp2\wtpwebapps\XXXRestAPI\WEB-INF\classes\com\XXX\dao\impl\XXXDaoImpl.class]: Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister; nested exception is  

2 个答案:

答案 0 :(得分:0)

经过一些谷歌搜索后我找到了答案,如果我们有getter方法,那么我们必须为每个属性设置setter方法,Hibernate假设将从数据库中读取值,所以为了设置这些值,它需要setter方法。

答案 1 :(得分:-1)

您的HistoryLogEntity

需要无参数构造函数
相关问题