最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

java - nested exception is org.hibernate.HibernateException: Found shared references to a collection - Stack Overflow

matteradmin3PV0评论

I have two entities like this:

@Data
@Builder
@Entity
@FieldDefaults(level = AccessLevel.PRIVATE)
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "refund_initiate",uniqueConstraints={@UniqueConstraint(columnNames={"device_code","installation_id"})})
public class RefundInitiate extends BaseEntity{
    ...
    @EqualsAndHashCode.Exclude
    @ToString.Exclude
    @OneToMany(mappedBy = "refundInitiate")
    List<RefundLogs> refundLogs;

}

@Data
@Builder
@Table(name = "refund_log")
@Entity
@NoArgsConstructor
@AllArgsConstructor
public class RefundLogs extends BaseEntity {
   @EqualsAndHashCode.Exclude
    @ToString.Exclude
    @ManyToOne
    @JoinColumn(name = "refund_initiate_id")
    RefundInitiate refundInitiate;
}

And a method is there:

@Override
    public Boolean approveRefund(Integer refundId) {
        Optional<RefundInitiate> refundInitiateOpt = refundInitiateRepo.findById(refundId);
        if (refundInitiateOpt.isEmpty())
            return false;
        RefundInitiate refundInitiate = refundInitiateOpt.get();
// some logic here but haven't touched the `RefundLogs` at all
        refundInitiateRepo.save(refundInitiate);
// some logic, again no changes on RefundLogs`
        return true;
    }

but when I call this method I get an error:

HibernateException: Found shared references to a collection: app.model.RefundInitiate.refundLogs] with root cause

.hibernate.HibernateException: Found shared references to a collection: app.model.RefundInitiate.refundLogs

According to the logs here at this point, an error occurs while saving: refundInitiateRepo.save(refundInitiate);

I suspect it is because of an old Hibernate version ('.hibernate:hibernate-envers:5.4.22.Final'), but in my other modules, such Bi-Directional mappings are working fine.

Please help me know how I can solve this issue, removing the mapping won't help because it's being used somewhere.

I tried using Cascade as PERSIT but didnt help.

Post a comment

comment list (0)

  1. No comments so far