Сущность 1 PriceListDuration.java
package com.Pricing.Pricing_App.model;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
@JsonPropertyOrder({"priceListId","statusCode","startDate","endDate","orgId"})
@Entity
@Table(name = "qp_price_lists_all_b_AV")
public class PriceListDuration {
@Id
@Column(name = "PRICE_LIST_ID")
private String priceListId;
@Column(name = "status_code")
private String statusCode;
@Column(name = "start_date")
private String startDate;
@Column(name = "end_Date")
private String endDate;
@Column(name = "org_id")
private String orgId;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "PRICE_LIST_ID", referencedColumnName = "PRICE_LIST_ID")
private PriceListDetail pricelistdetails;
public PriceListDetail getPricelistdetails() {
return pricelistdetails;
}
public void setPricelistdetails(PriceListDetail pricelistdetails) {
this.pricelistdetails = pricelistdetails;
}
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "PRICE_LIST_ID", referencedColumnName = "PRICE_LIST_ID")
private List<PriceListItem> priceListItems;
public List<PriceListItem> getPriceListItems() {
return priceListItems;
}
public void setPriceListItems(List<PriceListItem> priceListItems) {
this.priceListItems = priceListItems;
}
public String getPriceListId() {
return priceListId;
}
public void setPriceListId(String priceListId) {
this.priceListId = priceListId;
}
public String getStatusCode() {
return statusCode;
}
public void setStatusCode(String statusCode) {
this.statusCode = statusCode;
}
public String getStartDate() {
return startDate;
}
public void setStartDate(String startDate) {
this.startDate = startDate;
}
public String getEndDate() {
return endDate;
}
public void setEndDate(String endDate) {
this.endDate = endDate;
}
public String getOrgId() {
return orgId;
}
public void setOrgId(String orgId) {
this.orgId = orgId;
}
}
Сущность 2: PriceListItem.java
package com.Pricing.Pricing_App.model;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
@JsonPropertyOrder({"pricingUOMCode","lineTypeCode","primaryPricingUOMFlag","priceListId","itemId","priceListItemId"})
@Entity
@Table(name = "QP_PRICE_LIST_ITEMS_AV")
public class PriceListItem implements Serializable {
private static final long serialVersionUID = 1L;
public PriceListItem() {
super();
}
@Column(name = "price_list_item_id")
private String priceListItemId;
@Column(name = "pricing_uom_code")
private String pricingUOMCode;
@Column(name = "line_type_code")
private String lineTypeCode;
@Column(name = "primary_pricing_uom_flag")
private String primaryPricingUOMFlag;
@Column(name = "price_list_id")
private String priceListId;
@Id
@Column(name = "item_id")
private String itemId;
// For 1-1 mapping
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "item_id", referencedColumnName = "inventory_item_id")
private ItemDetail itemDetails;
public ItemDetail getItemDetails() {
return itemDetails;
}
public void setItemDetails(ItemDetail itemDetails) {
this.itemDetails = itemDetails;
}
public String getPricingUOMCode() {
return pricingUOMCode;
}
public void setPricingUOMCode(String pricingUOMCode) {
this.pricingUOMCode = pricingUOMCode;
}
public String getLineTypeCode() {
return lineTypeCode;
}
public void setLineTypeCode(String lineTypeCode) {
this.lineTypeCode = lineTypeCode;
}
public String getPrimaryPricingUOMFlag() {
return primaryPricingUOMFlag;
}
public void setPrimaryPricingUOMFlag(String primaryPricingUOMFlag) {
this.primaryPricingUOMFlag = primaryPricingUOMFlag;
}
public String getItemId() {
return itemId;
}
public void setItemId(String itemId) {
this.itemId = itemId;
}
}
Сущность 3: ItemDetail.java
package com.Pricing.Pricing_App.model;
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
@JsonPropertyOrder({"itemNumber","inventoryItemId","organizationId"})
@Entity
@Table(name = "egp_system_items_b_AV")
public class ItemDetail {
@Id
@Column(name = "inventory_item_id")
private String inventoryItemId;
@Column(name = "item_number")
private String itemNumber;
@Column(name = "organization_id")
private String organizationId;
public String getItemNumber() {
return itemNumber;
}
public void setItemNumber(String itemNumber) {
this.itemNumber = itemNumber;
}
public String getInventoryItemId() {
return inventoryItemId;
}
public void setInventoryItemId(String inventoryItemId) {
this.inventoryItemId = inventoryItemId;
}
public String getOrganizationId() {
return organizationId;
}
public void setOrganizationId(String organizationId) {
this.organizationId = organizationId;
}
}
У нас есть триОбъект, у которого Entity1 является владельцем, а E1-E2 имеет сопоставление 1-M, а E2-E3 имеет сопоставление 1-1.
My Controller:
package com.Pricing.Pricing_App.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.Pricing.Pricing_App.model.PriceListDuration;
import com.Pricing.Pricing_App.repository.PriceListDurationRepository;
@RestController
public class PriceListDurationController {
@Autowired
private PriceListDurationRepository priceListDurationRepository;
@GetMapping(value="/getBypriceListId")
public List<PriceListDuration> getBypriceListId(@RequestParam("priceListId") String priceListId) {
return priceListDurationRepository.findBypriceListId(priceListId);
}
}
Вот выход JSON
[
{
"priceListId": "300002009417575",
"statusCode": "APPROVED",
"startDate": "1998-12-31 00:00:00",
"endDate": null,
"orgId": "300001096431127",
"pricelistdetails": {
"priceListId": "300002009417575",
"name": "COMMERCIAL PRICELIST",
"description": "COMMERCIAL PRICELIST",
"language": "US"
},
"priceListItems": [
{
"pricingUOMCode": "zzx",
"lineTypeCode": "ORA_BUY",
"primaryPricingUOMFlag": "Y",
"itemId": "100000763258696",
"itemDetails": {
"itemNumber": "SAM-SOLO-P2-PT",
"inventoryItemId": "100000763258696",
"organizationId": "300000245868293"
}
},
{
"pricingUOMCode": "zzx",
"lineTypeCode": "ORA_BUY",
"primaryPricingUOMFlag": "Y",
"itemId": "100000763259581",
"itemDetails": null
}
]
}
]
Как выможно увидеть ItemDetails (из сущности 3) является нулевым.Я хочу ограничить блок priceListItems, который имеет ItemDetails как ноль.findBypriceListId возвращает мне вывод JSON, как указано выше.Вывод также имеет "itemDetails": null.Я не хочу никакого блока, который является нулевым в результате.Ожидаемый JSON не должен иметь
{
"pricingUOMCode": "zzx",
"lineTypeCode": "ORA_BUY",
"primaryPricingUOMFlag": "Y",
"itemId": "100000763259581",
"itemDetails": null
}
Кажется, текущая реализация выполняет внешнее соединение