ClassCastException: HashMap can not be cast to String thrown by Hibernate Envers when persisting self-referencing many-to-many entity in JBoss EAP 5 and 6

Solution Unverified - Updated -

Issue

Given an entity like the following:

@Audited
@Entity()
@Table(name = "rh_info_complaint")
public class RHInfoComplaint {

    private Integer id;
    private String originalId;
    private List<RHInfoComplaint> relatedComplaints = new ArrayList<RHInfoComplaint>(1);

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
    @AuditJoinTable(name = "aud_info_complaint_related")
    @Fetch(FetchMode.SELECT)
    @ForeignKey(name = "fk_ic_ic_relcompid")
    @JoinColumn(name = "related_complaint_id")
    @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    public List<RHInfoComplaint> getRelatedComplaints() {
        return relatedComplaints;
    }

    public void setRelatedComplaints(List<RHInfoComplaint> relatedComplaints) {
        this.relatedComplaints = relatedComplaints;
    }

    @Column(name = "original_id", insertable=true, nullable=false, updatable=true)
    public String getOriginalId() {
        return originalId;
    }

    public void setOriginalId(String originalId) {
        this.originalId = originalId;
    }
}

the following ClassCastException is thrown by Hibernate Envers when attempting to persist a new instance which references another new instance:

java.lang.ClassCastException: java.util.HashMap cannot be cast to java.lang.String

`

Environment

  • JBoss Enterprise Application Platform (EAP) 5
  • JBoss Enterprise Application Platform (EAP) 6

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In
Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.