i create a table audit log using Hibernate Envers, and i use Spring Data Envers as my library, when i save/update/delete it successfully saved the log in my autid_log table, but when i want to retrive the log data, i got infinite loop of error, how can i do this properly? here is my code :
Here is my controller :
@GetMapping("/getPartnerRelationshipLog/{partnerId}")
public ResponseEntity<?> getPartnerRelationshipLog(@PathVariable Long partnerId) {
// Long id = partner.getId();
Revisions<Integer,Partner> history = partnerService.findRelationLog(partnerId);
return ResponseEntity.ok(history);
}
here is my Partner.java model : package com.example.envers.auditing.Model;
@Data
@Entity
@Audited
@EntityListeners(AuditingEntityListener.class)
@Table(name = "msPartner")
public class Partner {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long id;
public String partnerCode;
public String partnerName;
@CreatedDate
private Date createDate;
@LastModifiedDate
private Date lastModifiedDate;
@CreatedBy
private String createdBy;
@LastModifiedBy
private String modifiedBy;
@OneToMany(mappedBy = "partner", cascade = CascadeType.ALL)
public List<PartnerShipment> partnerShipment;
}
and here is my PartnerShipment.java :
@Data
@Entity
@Audited
@EntityListeners(AuditingEntityListener.class)
@Table(name = "msPartnerShipment")
public class PartnerShipment {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long id;
public String partnerShipmentCode;
public String partnerShipmentAddress;
@JsonIgnore
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "partnerId")
// @NotAudited
public Partner partner;
@CreatedDate
private Date createDate;
@LastModifiedDate
private Date lastModifiedDate;
@CreatedBy
private String createdBy;
@LastModifiedBy
private String modifiedBy;
}
and here is my service :
public Revisions<Integer,Partner> findRelationLog(Long id) {
Revisions<Integer,Partner> partner = partnerRepository.findRevisions(id);
return partner;
}
here is my Repository :
@Repository
public interface PartnerRepository extends RevisionRepository<Partner, Long, Integer>, JpaRepository<Partner, Long > {
}
and here is my Application.java
@SpringBootApplication
@EnableJpaRepositories(repositoryFactoryBeanClass = EnversRevisionRepositoryFactoryBean.class)
@EnableJpaAuditing
public class AuditingApplication {
public static void main(String[] args) {
SpringApplication.run(AuditingApplication.class, args);
}
}
when i get the data with id = 1, i got something like infinite error of loop, start with java.lang.StackOverflowError: null, what i see in my terminal only this :
java.lang.StackOverflowError: null
at com.example.envers.auditing.Model.PartnerShipment.hashCode(PartnerShipment.java:33) ~[classes/:na]
at java.util.AbstractList.hashCode(AbstractList.java:541) ~[na:1.8.0_241]
at org.hibernate.envers.internal.entities.mapper.relation.lazy.proxy.CollectionProxy.hashCode(CollectionProxy.java:131) ~[hibernate-envers-5.4.17.Final.jar:5.4.17.Final]
at com.example.envers.auditing.Model.Partner.hashCode(Partner.java:31) ~[classes/:na]
at com.example.envers.auditing.Model.PartnerShipment.hashCode(PartnerShipment.java:33) ~[classes/:na]
at java.util.AbstractList.hashCode(AbstractList.java:541) ~[na:1.8.0_241]
at org.hibernate.envers.internal.entities.mapper.relation.lazy.proxy.CollectionProxy.hashCode(CollectionProxy.java:131) ~[hibernate-envers-5.4.17.Final.jar:5.4.17.Final]
at com.example.envers.auditing.Model.Partner.hashCode(Partner.java:31) ~[classes/:na]
at com.example.envers.auditing.Model.PartnerShipment.hashCode(PartnerShipment.java:33) ~[classes/:na]
at java.util.AbstractList.hashCode(AbstractList.java:541) ~[na:1.8.0_241]
at org.hibernate.envers.internal.entities.mapper.relation.lazy.proxy.CollectionProxy.hashCode(CollectionProxy.java:131) ~[hibernate-envers-5.4.17.Final.jar:5.4.17.Final]
at com.example.envers.auditing.Model.Partner.hashCode(Partner.java:31) ~[classes/:na]
at com.example.envers.auditing.Model.PartnerShipment.hashCode(PartnerShipment.java:33) ~[classes/:na]
at java.util.AbstractList.hashCode(AbstractList.java:541) ~[na:1.8.0_241]
at org.hibernate.envers.internal.entities.mapper.relation.lazy.proxy.CollectionProxy.hashCode(CollectionProxy.java:131) ~[hibernate-envers-5.4.17.Final.jar:5.4.17.Final]
at com.example.envers.auditing.Model.Partner.hashCode(Partner.java:31) ~[classes/:na]
at com.example.envers.auditing.Model.PartnerShipment.hashCode(PartnerShipment.java:33) ~[classes/:na]
at java.util.AbstractList.hashCode(AbstractList.java:541) ~[na:1.8.0_241]
at org.hibernate.envers.internal.entities.mapper.relation.lazy.proxy.CollectionProxy.hashCode(CollectionProxy.java:131) ~[hibernate-envers-5.4.17.Final.jar:5.4.17.Final]
at com.example.envers.auditing.Model.Partner.hashCode(Partner.java:31) ~[classes/:na]
at com.example.envers.auditing.Model.PartnerShipment.hashCode(PartnerShipment.java:33) ~[classes/:na]
at java.util.AbstractList.hashCode(AbstractList.java:541) ~[na:1.8.0_241]
at org.hibernate.envers.internal.entities.mapper.relation.lazy.proxy.CollectionProxy.hashCode(CollectionProxy.java:131) ~[hibernate-envers-5.4.17.Final.jar:5.4.17.Final]
what did i miss to avoid this error?