Hibernate envers引发ClassCastException:HashMap无法转换为Integer

问题描述 投票:2回答:1

我已经配置为在SpringBoot 2.x应用程序中使用Hibernate envers。这是我的属性文件中的配置。

spring.jpa.properties.hibernate.hbm2ddl.auto=update
spring.jpa.properties.org.hibernate.envers.audit_strategy=org.hibernate.envers.strategy.ValidityAuditStrategy
spring.jpa.properties.org.hibernate.envers.audit_table_prefix=private_
spring.jpa.properties.org.hibernate.envers.default_schema=ims_audit
spring.jpa.properties.org.hibernate.envers.audit_table_suffix=

我的实体类如下:

@Audited
@Entity
public class Respondent extends Auditable<Respondent> implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @Column(name="respondent_id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer respondentId;

    @Column(name="address_line1")
    private String addressLine1;

    @Column(name="address_line2")
    private String addressLine2;

    private String cage;

    private String city;

    private String country;

    private String county;

    private String duns;

    @Column(name="eeo1_hdq_nbr")
    private String eeo1HdqNbr;

    @Column(name="eeo1_unit_nbr")
    private String eeo1UnitNbr;

    private String ein;

    @Column(name="email_address")
    private String emailAddress;

    @Column(name="eml_compatability_grade")
    private BigDecimal emlCompatabilityGrade;

    @Column(name="eml_employer_id")
    private Integer emlEmployerId;

    @Column(name="eml_state")
    private String emlState;

    @Column(name="eml_verification_on")
    private LocalDateTime emlVerificationOn;

    private String extension;

    private String fax;

    @Column(name="institution_type")
    private String institutionType;

    private String mediation;

    @Column(name="naics_code")
    private String naicsCode;

    private String name;

    @Column(name="number_of_employees")
    private String numberOfEmployees;

    @Column(name="original_id")
    private Integer originalId;

    private String phone;

    @Column(name="position_statement_due")
    private LocalDateTime positionStatementDue;

    @Column(name="respondent_password")
    private String respondentPassword;

    private String state;

    @Column(name="zip_code")
    private String zipCode;

    @NotAudited
    @OneToOne (mappedBy = "respondent")
    private ChargeInquiry chargeInquiry;

    @NotAudited
    @OneToMany (mappedBy = "respondent")
    private Set<AdditionalAddress> additionalAddressSet;

在插入记录时,出现此错误:

Hibernate: insert into ims_audit.private_Respondent (REVTYPE, REVEND, address_line1, address_line2, cage, city, country, county, duns, eeo1_hdq_nbr, eeo1_unit_nbr, ein, email_address, eml_compatability_grade, eml_employer_id, eml_state, eml_verification_on, extension, fax, institution_type, mediation, naics_code, name, number_of_employees, original_id, phone, position_statement_due, respondent_password, state, zip_code, respondent_id, REV) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2020-02-20 13:47:24 TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [1] as [INTEGER] - [0]
2020-02-20 13:47:24 TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [2] as [INTEGER] - [null]
2020-02-20 13:47:24 TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [3] as [VARCHAR] - [null]
2020-02-20 13:47:24 TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [4] as [VARCHAR] - [null]
2020-02-20 13:47:24 TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [5] as [VARCHAR] - [null]
2020-02-20 13:47:24 TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [6] as [VARCHAR] - [null]
2020-02-20 13:47:24 TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [7] as [VARCHAR] - [null]
2020-02-20 13:47:24 TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [8] as [VARCHAR] - [null]
2020-02-20 13:47:24 TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [9] as [VARCHAR] - [null]
2020-02-20 13:47:24 TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [10] as [VARCHAR] - [null]
2020-02-20 13:47:24 TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [11] as [VARCHAR] - [null]
2020-02-20 13:47:24 TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [12] as [VARCHAR] - [null]
2020-02-20 13:47:24 TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [13] as [VARCHAR] - [null]
2020-02-20 13:47:24 TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [14] as [NUMERIC] - [null]
2020-02-20 13:47:24 TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [15] as [INTEGER] - [null]
2020-02-20 13:47:24 TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [16] as [VARCHAR] - [null]
2020-02-20 13:47:24 TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [17] as [TIMESTAMP] - [null]
2020-02-20 13:47:24 TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [18] as [VARCHAR] - [null]
2020-02-20 13:47:24 TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [19] as [VARCHAR] - [null]
2020-02-20 13:47:24 TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [20] as [VARCHAR] - [null]
2020-02-20 13:47:24 TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [21] as [VARCHAR] - [null]
2020-02-20 13:47:24 TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [22] as [VARCHAR] - [null]
2020-02-20 13:47:24 TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [23] as [VARCHAR] - [abc corp]
2020-02-20 13:47:24 TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [24] as [VARCHAR] - [null]
2020-02-20 13:47:24 TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [25] as [INTEGER] - *****[{REV=DefaultRevisionEntity(id = 56, revisionDate = Feb 20, 2020 1:47:24 PM), respondentId=50}]*
2020-02-20 13:47:24 ERROR org.hibernate.AssertionFailure - HHH000099: an assertion failure occurred (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session): java.lang.ClassCastException: java.util.HashMap cannot be cast to java.lang.Integer
java.lang.ClassCastException: java.util.HashMap cannot be cast to java.lang.Integer****

我不明白为什么它试图将“ DefaultRevisionEntity”的哈希图插入到作为整数的REV列中。

hibernate hibernate-envers
1个回答
0
投票

问题是,属性名称originalId由Hibernate内部使用,请参阅:

将属性originalId重命名为其他名称可解决此问题。

© www.soinside.com 2019 - 2024. All rights reserved.