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.