我最近将 Spring Boot 从 1.5.2 Release 升级到 Spring Boot 2.1.3 Release。之后,我的应用程序无法运行,原因是:org.springframework.data.mapping.PropertyReferenceException: No property getPayments found for type DailyPaymentOrgFunc!
这是我的实体:
import lombok.Data;
import org.hibernate.annotations.NamedNativeQuery;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import java.util.Date;
@Data
@Entity
@NamedNativeQuery(name = Function.ORG_FUNC_NAME,query = Function.ORG_FUNC,
callable = true,resultClass = DailyPaymentOrgFunc.class)
public class DailyPaymentOrgFunc{
@Id
@Column(name = "RECEIPT_NUMBER")
private String receiptNumber;
@Column(name = "AMOUNT")
private Float amount;
@Column(name = "SERVICE_CODE")
private Integer serviceCode;
@Column(name = "PAYMENT_DATE")
private Date paymentDate;
@Column(name = "PAYMENT_TRN")
private String paymentTrn;
@Column(name = "ORG_CODE")
private Integer orgCode;
}
存储库:
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.query.Param;
import java.util.List;
public interface DailyPaymentOrgRepository extends JpaRepository<DailyPaymentOrgFunc,String> {
List<DailyPaymentOrgFunc> getPayments(@Param("orgCode") Integer orgCode);
}
常量类:
public class Function {
public static final String ORG_FUNC_NAME = "DailyPaymentOrgFunc.getPayments";
public static final String ORG_FUNC ="{ ? = call DAILY_PAYMENT_FUNC(null,2,:orgCode,null)}";
private Function() throws IllegalAccessException {
throw new IllegalAccessException("Function is a utility class!!!");
}
}
我调试了代码,发现问题出在org.springframework.data.util.TypeDiscoverer.class的这段代码,这段代码返回(TypeInformation)((Optional)this.fieldTypes.computeIfAbsent(fieldname, this: :getPropertyInformation)).orElse((Object)null); return Optional null,这就是它不起作用的原因,但我不知道如何解决这个问题。
@Nullable
public TypeInformation<?> getProperty(String fieldname) {
int separatorIndex = fieldname.indexOf(46);
if (separatorIndex == -1) {
return (TypeInformation)((Optional)this.fieldTypes.computeIfAbsent(fieldname, this::getPropertyInformation)).orElse((Object)null);
} else {
String head = fieldname.substring(0, separatorIndex);
TypeInformation<?> info = this.getProperty(head);
return info == null ? null : info.getProperty(fieldname.substring(separatorIndex + 1));
}
}