[英]I am using JpaRepository in my application.And in Implementation class im calling the findAll(Example<T>) but its not giving me proper response
This is my repository interface这是我的存储库界面
public interface InvoiceHeaderRepository extends JpaRepository<InvoiceHeaderDo, Integer>{
}
And this the function where I'm calling the findAll(Example).这是我调用 findAll(Example) 的函数。
public List<InvoiceHeaderDto> filterByKeys(InvoiceHeaderDto dto) {
ModelMapper mapper = new ModelMapper();
List<InvoiceHeaderDto> dtoList = new ArrayList<>();
try {
Example<InvoiceHeaderDo> example = Example.of(importDto(dto));
List<InvoiceHeaderDo> entityList = invoiceHeaderRepository.findAll(example);
for (InvoiceHeaderDo invoiceHeaderDo : entityList) {
dtoList.add(mapper.map(invoiceHeaderDo, InvoiceHeaderDto.class));
}
} catch (Exception e) {
e.printStackTrace();
}
return dtoList;
}
And I have getter setter in my Entity Class.So when Im hitting from postman its not working and automatically taking one parameter which I'm not passing from postman.This the an object of this Entity.我的实体类中有 getter setter。所以当我从邮递员那里打来时,它不起作用并自动采用一个我没有从邮递员那里传递的参数。这是这个实体的一个对象。
{
"requestId": "APA-000001",
"compCode": 11,
"refDocNum": 4500000842,
"extInvNum": "410E02035B",
"createdAt": 1519948800000,
"clerkId": null,
"clerkEmail": null,
"channelType": null,
"refDocCat": null,
"invoiceType": "Invoice",
"invoiceTotal": "33300.84",
"sapInvoiceNumber": null,
"fiscalYear": null,
"currency": "USD",
"paymentTerms": null,
"taxAmount": null,
"shippingCost": 55.0,
"lifecycleStatus": null,
"taskStatus": null,
"version": null,
"emailFrom": null,
"vendorId": 14775
}
So when I'm trying to filter on like this所以当我试图像这样过滤时
{
"requestId": "APA-000001"
}
its giving empty list.它给出了空列表。 This is the log where its taking another field also.这是它也采取另一个领域的日志。
2020-03-12T05:06:24.681+0000 [APP/PROC/WEB/0] OUT Hibernate:
2020-03-12T05:06:24.681+0000 [APP/PROC/WEB/0] OUT select
2020-03-12T05:06:24.681+0000 [APP/PROC/WEB/0] OUT invoicehea0_.request_id as request_id1_1_,
2020-03-12T05:06:24.681+0000 [APP/PROC/WEB/0] OUT invoicehea0_.vendor_id as vendor_id2_1_,
2020-03-12T05:06:24.681+0000 [APP/PROC/WEB/0] OUT invoicehea0_.channel_type as channel_type3_1_,
2020-03-12T05:06:24.681+0000 [APP/PROC/WEB/0] OUT invoicehea0_.clerk_email as clerk_email4_1_,
2020-03-12T05:06:24.681+0000 [APP/PROC/WEB/0] OUT invoicehea0_.clerk_id as clerk_id5_1_,
2020-03-12T05:06:24.681+0000 [APP/PROC/WEB/0] OUT invoicehea0_.comp_code as comp_code6_1_,
2020-03-12T05:06:24.681+0000 [APP/PROC/WEB/0] OUT invoicehea0_.created_at as created_at7_1_,
2020-03-12T05:06:24.681+0000 [APP/PROC/WEB/0] OUT invoicehea0_.currency as currency8_1_,
2020-03-12T05:06:24.681+0000 [APP/PROC/WEB/0] OUT invoicehea0_.email_from as email_from9_1_,
2020-03-12T05:06:24.681+0000 [APP/PROC/WEB/0] OUT invoicehea0_.ext_inv_num as ext_inv_num10_1_,
2020-03-12T05:06:24.681+0000 [APP/PROC/WEB/0] OUT invoicehea0_.fiscal_year as fiscal_year11_1_,
2020-03-12T05:06:24.681+0000 [APP/PROC/WEB/0] OUT invoicehea0_.invoice_total as invoice_total12_1_,
2020-03-12T05:06:24.681+0000 [APP/PROC/WEB/0] OUT invoicehea0_.invoice_type as invoice_type13_1_,
2020-03-12T05:06:24.681+0000 [APP/PROC/WEB/0] OUT invoicehea0_.lifecycle_status as lifecycle_status14_1_,
2020-03-12T05:06:24.681+0000 [APP/PROC/WEB/0] OUT invoicehea0_.payment_terms as payment_terms15_1_,
2020-03-12T05:06:24.681+0000 [APP/PROC/WEB/0] OUT invoicehea0_.ref_doc_cat as ref_doc_cat16_1_,
2020-03-12T05:06:24.681+0000 [APP/PROC/WEB/0] OUT invoicehea0_.ref_doc_num as ref_doc_num17_1_,
2020-03-12T05:06:24.681+0000 [APP/PROC/WEB/0] OUT invoicehea0_.sap_invoice_number as sap_invoice_number18_1_,
2020-03-12T05:06:24.681+0000 [APP/PROC/WEB/0] OUT invoicehea0_.shipping_cost as shipping_cost19_1_,
2020-03-12T05:06:24.681+0000 [APP/PROC/WEB/0] OUT invoicehea0_.task_status as task_status20_1_,
2020-03-12T05:06:24.681+0000 [APP/PROC/WEB/0] OUT invoicehea0_.tax_amount as tax_amount21_1_,
2020-03-12T05:06:24.681+0000 [APP/PROC/WEB/0] OUT invoicehea0_.version as version22_1_
2020-03-12T05:06:24.681+0000 [APP/PROC/WEB/0] OUT from
2020-03-12T05:06:24.681+0000 [APP/PROC/WEB/0] OUT apautomation.invoice_header invoicehea0_
2020-03-12T05:06:24.681+0000 [APP/PROC/WEB/0] OUT where
2020-03-12T05:06:24.681+0000 [APP/PROC/WEB/0] OUT invoicehea0_.request_id=?
2020-03-12T05:06:24.681+0000 [APP/PROC/WEB/0] OUT and invoicehea0_.ref_doc_num=0
this is my Controller这是我的控制器
@PostMapping("/filter")
public List<InvoiceHeaderDto> filterGetAll(@RequestBody InvoiceHeaderDto dto){
return headerService.filterByKeys(dto);
}
Here is the Entity class这是实体类
@Entity
@Table(name="Invoice_Header")
public class InvoiceHeaderDo {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "InvoiceHeader")
@GenericGenerator(name = "InvoiceHeader", strategy = "com.incture.ap.sequences.InvoiceHeaderSequenceGenerator", parameters = {
@Parameter(name = InvoiceHeaderSequenceGenerator.INCREMENT_PARAM, value = "1"), @Parameter(name = InvoiceHeaderSequenceGenerator.VALUE_PREFIX_PARAMETER, value = "APA-"),
@Parameter(name = InvoiceHeaderSequenceGenerator.NUMBER_FORMAT_PARAMETER, value = "%06d"),
@Parameter(name = InvoiceHeaderSequenceGenerator.SEQUENCE_PARAM,value="INVOICE_HEADER_SEQ")})
@Column(name="REQUEST_ID")
private String requestId;
@Column(name="COMP_CODE")
private Integer compCode;
@Column(name="REF_DOC_NUM")
private long refDocNum;
@Column(name="EXT_INV_NUM")
private String extInvNum;
@Column(name="CREATED_AT")
private Date createdAt;
@Column(name="VENDOR_ID")
private Integer VendorId;
@Column(name="CLERK_ID")
private Integer clerkId;
@Column(name="CLERK_EMAIL")
private String clerkEmail;
@Column(name="CHANNEL_TYPE")
private String channelType;
@Column(name="REF_DOC_CAT")
private String refDocCat;
@Column(name="INVOICE_TYPE")
private String invoiceType;
@Column(name="INVOICE_TOTAL")
private String invoiceTotal;
@Column(name="SAP_INVOICE_NUMBER")
private Integer sapInvoiceNumber;
@Column(name="FISCAL_YEAR")
private String fiscalYear;
@Column(name="CURRENCY")
private String currency;
@Column(name="PAYMENT_TERMS")
private String paymentTerms;
@Column(name="TAX_AMOUNT")
private Integer taxAmount;
@Column(name="SHIPPING_COST")
private Double shippingCost;
@Column(name="LIFECYCLE_STATUS")
private String lifecycleStatus;
@Column(name="TASK_STATUS")
private String taskStatus;
@Column(name="VERSION")
private Integer version;
@Column(name="EMAIL_FROM")
private String emailFrom;
here is the dto这是 dto
public class InvoiceHeaderDto {
private String requestId;
private Integer compCode;
private long refDocNum;
private String extInvNum;
private Date createdAt;
private Integer VendorId;
private Integer clerkId;
private String clerkEmail;
private String channelType;
private String refDocCat;
private String invoiceType;
private String invoiceTotal;
private Integer sapInvoiceNumber;
private String fiscalYear;
private String currency;
private String paymentTerms;
private Integer taxAmount;
private Double shippingCost;
private String lifecycleStatus;
private String taskStatus;
private Integer version;
private String emailFrom;
public String getRequestId() {
return requestId;
}
public void setRequestId(String requestId) {
this.requestId = requestId;
}
public Integer getCompCode() {
return compCode;
}
public void setCompCode(Integer compCode) {
this.compCode = compCode;
}
public long getRefDocNum() {
return refDocNum;
}
public void setRefDocNum(long refDocNum) {
this.refDocNum = refDocNum;
}
public String getExtInvNum() {
return extInvNum;
}
public void setExtInvNum(String extInvNum) {
this.extInvNum = extInvNum;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Integer getVendorId() {
return VendorId;
}
public void setVendorId(Integer vendorId) {
VendorId = vendorId;
}
public Integer getClerkId() {
return clerkId;
}
public void setClerkId(Integer clerkId) {
this.clerkId = clerkId;
}
public String getClerkEmail() {
return clerkEmail;
}
public void setClerkEmail(String clerkEmail) {
this.clerkEmail = clerkEmail;
}
public String getChannelType() {
return channelType;
}
public void setChannelType(String channelType) {
this.channelType = channelType;
}
public String getRefDocCat() {
return refDocCat;
}
public void setRefDocCat(String refDocCat) {
this.refDocCat = refDocCat;
}
public String getInvoiceType() {
return invoiceType;
}
public void setInvoiceType(String invoiceType) {
this.invoiceType = invoiceType;
}
public String getInvoiceTotal() {
return invoiceTotal;
}
public void setInvoiceTotal(String invoiceTotal) {
this.invoiceTotal = invoiceTotal;
}
public Integer getSapInvoiceNumber() {
return sapInvoiceNumber;
}
public void setSapInvoiceNumber(Integer sapInvoiceNumber) {
this.sapInvoiceNumber = sapInvoiceNumber;
}
public String getFiscalYear() {
return fiscalYear;
}
public void setFiscalYear(String fiscalYear) {
this.fiscalYear = fiscalYear;
}
public String getCurrency() {
return currency;
}
public void setCurrency(String currency) {
this.currency = currency;
}
public String getPaymentTerms() {
return paymentTerms;
}
public void setPaymentTerms(String paymentTerms) {
this.paymentTerms = paymentTerms;
}
public Integer getTaxAmount() {
return taxAmount;
}
public void setTaxAmount(Integer taxAmount) {
this.taxAmount = taxAmount;
}
public Double getShippingCost() {
return shippingCost;
}
public void setShippingCost(Double shippingCost) {
this.shippingCost = shippingCost;
}
public String getLifecycleStatus() {
return lifecycleStatus;
}
public void setLifecycleStatus(String lifecycleStatus) {
this.lifecycleStatus = lifecycleStatus;
}
public String getTaskStatus() {
return taskStatus;
}
public void setTaskStatus(String taskStatus) {
this.taskStatus = taskStatus;
}
public Integer getVersion() {
return version;
}
public void setVersion(Integer version) {
this.version = version;
}
public String getEmailFrom() {
return emailFrom;
}
public void setEmailFrom(String emailFrom) {
this.emailFrom = emailFrom;
}
As you can see, you are searching not only by id
but by some ref_doc_num
as well.如您所见,您不仅通过id
进行搜索,还通过一些ref_doc_num
进行搜索。 Because it is of type long
it cannot be null
but will be 0
uponi init.因为它是long
类型long
所以它不能为null
但在初始化时为0
。 That results in additional predicate in query and obvious mismatch, as presented entity data does not contain ref_doc_num==0
这会导致查询中的额外谓词和明显的不匹配,因为呈现的实体数据不包含ref_doc_num==0
@Column(name="REF_DOC_NUM")
private long refDocNum;
2020-03-12T05:06:24.681+0000 [APP/PROC/WEB/0] OUT where
2020-03-12T05:06:24.681+0000 [APP/PROC/WEB/0] OUT invoicehea0_.request_id=?
2020-03-12T05:06:24.681+0000 [APP/PROC/WEB/0] OUT and invoicehea0_.ref_doc_num=0
Try changing refDocNum
to Long
to allow null values.尝试将refDocNum
更改为Long
以允许空值。
Pro tip of the day: Use start using Lombok to avoid boilerplate code.专业提示:使用开始使用Lombok以避免样板代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.