'Failed to read value from property in Java
de.danielbechler.diff.introspection.PropertyReadException: Failed to read value from property 'areaCode' of type 'com.abhishekpandey.jsonWriterReader.domain.FundRequest$HibernateProxy$bwLejRpl'
There are 2 objects which I am trying to compare.
- mappedObject is the request from the API (Values are below in the image)
- previousObject is the Data fetched from the DB with the ID from the API Request mapped Object
This is how I am mapping my request to the FundRequest.Class
final List<U> mappedRequests = requestToEntityMapper.map(requests, FundRequest); --> Calling this from another method which invokes the below Function to map
private static final Function<FundRequest, FundRequest> newRequestMapper =
request ->
NewFundRequest.builder()
.descriptorCode(request.getDescriptorCode())
.areaCode(request.getAreaCode())
.accountingCode(request.getAccountingCode())
.fundCode(request.getFundCode())
.loadStatusCode(request.getLoadStatusCode())
.userId(request.getUserId())
.createdAt(request.getCreatedAt())
.lastUpdated(request.getLastUpdated())
.build();
My FundRequest.Class
package com.abhishekpandey.jsonWriterReader.domain;
import java.sql.Timestamp;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.annotations.Entity;
import org.springframework.util.StringUtils;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Entity
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(name="FUND_REQUEST", schema="MYFUNDDB")
public class FundRequest implements Storable {
@Id
@Column(name = "DESC_CD")
private String descriptorCode;
@Column(name = "AREA_CD")
private String areaCode = "A";
@Column(name= "ACCT_CD")
private String accountingCode = StringUtils.EMPTY;
@Column(name = "FUND_CD")
private String fundCode = StringUtils.EMPTY;
@Column(name = "LOAD_STAT_C")
private Short loadStatusCode = 1;
@Column(name = "USER_I")
private String userId;
@Column(name = "MOD_TS")
public Timestamp lastUpdated;
@Column(name = "CREATION_TS")
public Timestamp createdAt;
@Override
public String getKey() {
return String.valueOf(descriptorCode);
}
}
This is how I am getting my previousObject and then passing both objects to another method where it will find and returns the changes
Storable previousObject = null;
try {
previousObject = repository.getById(mappedObject.getKey());
} catch (Exception e) {
System.out.println("error: " + e);
}
List<AuditChange> changes = findChangesInObject(previousObject, mappedObject);
I am using ObjectDifferBuilder in my findChangesInObject() then it throws PropertyReadException exception for areaCode, as it is not able to access the property.
private List<AuditChange> findChangesInObject(final Storable previousObject, final Storable mappedObject) {
List<AuditChange> objectChanges = new ArrayList<>();
DiffNode diff = null;
try {
diff = ObjectDifferBuilder.buildDefault().compare(previousObject, mappedObject);
} catch (Exception exception) {
// Catch unexpected Exceptions.
exception.getStackTrace();
if (exception.getCause() != null) {
exception.getCause();
}
}
diff.visit((diffNode, visit) -> {
AuditChange change = AuditChange.builder().fieldName(diffNode.getPropertyName())
.previousValue(String.valueOf(diffNode.canonicalGet(previousObject)).trim())
.currentValue(String.valueOf(diffNode.canonicalGet(mappedObject)).trim()).build();
objectChanges.add(change);
});
return objectChanges;
}
I am getting PropertyReadException --> InvocationTargetException --> EntityNotFoundException
I am sharing the images from the variables which has exceptions and values for previous & mapped objects.
Also I get this InvocationExcption when I try to see the values of the previousObject in Debug Mode.

I tried to figure out and found this article, where it talks about issues of using Lombok and Hibernate annotations together and tried removing the @Data and using @Getter, @Setter but still the issue remains. I am blocked on this from past 3 days and not able to find any solution.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|


