[英]Kotlin - Could not write JSON: Conflicting getter definitions for property (HttpMessageNotWritableException)
[英]I am getting an error (HttpMessageNotWritableException: Could not write JSON: Invalid property '' of bean class) when using getter method
我正在使用接口LoanInterface.java
来根据请求显示值。 我的问题是我遇到了这个错误:
Invalid property 'accountNumber' of bean class [com.meteor.coral.portfolio.modules.loanaccount.domain.Loan$HibernateProxy$Vm2InzHB]:
Getter for property 'accountNumber' threw exception; nested exception is java.lang.reflect.InvocationTargetException;
nested exception is com.fasterxml.jackson.databind.JsonMappingException: Invalid property 'accountNumber' of bean class
[com.meteor.coral.portfolio.modules.loanaccount.domain.Loan$HibernateProxy$Vm2InzHB]: Getter for property 'accountNumber' threw exception;
nested exception is java.lang.reflect.InvocationTargetException
(through reference chain: org.springframework.data.domain.PageImpl["content"]
->java.util.Collections$UnmodifiableRandomAccessList[0]->com.sun.proxy.$Proxy394["loanId"]->com.sun.proxy.$Proxy395["accountNumber"])]
这是我的LoanInterface.java
@JsonPropertyOrder({
"id",
"accountNumber"
})
public interface LoanInterface {
public Long getId();
public String getAccountNumber();
}
这是 model, Loan.java
,我想在其中获取字段:
@Entity
@Component
@Data
@EqualsAndHashCode(callSuper = false)
@Table(name = "m_loan", uniqueConstraints = { @UniqueConstraint(columnNames = { "account_no" }, name = "loan_account_no_UNIQUE"),
@UniqueConstraint(columnNames = { "external_id" }, name = "loan_externalid_UNIQUE") })
public class Loan extends AbstractPersistableCustom<Long> {
@Column(name = "account_no", length = 20, unique = true, nullable = false)
private String accountNumber;
}
id 位于AbstractPersistableCustom
class 内部,该内部正在扩展Loan.java
。
这是BillingProcessInterface.java
我称之为LoanInterface.java
@JsonPropertyOrder({
"id",
"loanId"
})
public interface BillingProcessInterface {
public Long getId();
public LoanInterface getLoanId();
}
BillingProcess.java
model,我称之为Loan.java
@Entity
@Table(name = "m_billing")
@Data
@EqualsAndHashCode(callSuper = true)
public class BillingProcess extends AbstractPersistableCustom<Long> {
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "loan_id", nullable = false)
private Loan loanId;
}
但是,当我尝试从Loan.java
中获取其他字段时,例如accountNumber
,我收到了错误消息。
有谁知道如何解决这个问题? 关于注释的使用,我是否过度使用或缺少某些东西? 谢谢你。
看起来您正在尝试从延迟加载的字段进行投影。
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "loan_id", nullable = false)
private Loan loanId;
投影发生在事务之外,因此您必须在使用它们之前加载字段。 您可以通过将获取类型更改为 EAGER 或在存储库中使用“@EntityGraph”注释来指定应加载哪些惰性字段来实现它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.