最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览0评论

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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论