2016-06-16 15 views
0

Ich mache einfache Testanwendung, um Morphia Fähigkeiten zu erforschen. Im Moment versuche ich eine einfache Aggregation Abfrage auf SaleStatistics Sammlung. Die Abfrage ist Filter nach Produktbezeichnung und Gruppierung nach Produktfamilie und Unterfamilie und Summe Menge und Menge. Das Problem ist, dass Morphia eine korrekte Ersetzung der Eigenschaftsnamen in der $ match-Phase gemäß den in den Klassen definierten @Property-Zuordnungen durchführte, aber nicht die gleiche Ersetzung in der $ group-Phase vornahm. In diesem Fall wurde mit ihm der Eigenschaft Strings direkt in der Aggregationsdefinition verwendet, wie Sie in diesem Code snipped aus der Logging-Konsole sehen:Warum Morphia @Property-Wert nicht in der Aggregation verwendet?

2016-06-16 10:09:22 DEBUG AggregationPipelineImpl:36 - stages = [{ "$match" : { "Producto.Denominacion" : "MAGNA"}}, { "$group" : { "_id" : { "productFamily" : "$product.productFamily" , "productSubfamily" : "$product.productSubFamily"} , "saleStatisticsQuantity" : { "$sum" : "$quantity"} , "saleStatisticsAmount" : { "$sum" : "$amount"}}}] 

Hier ist mein Entity-Mapping:

@SuppressWarnings("serial") 
@Entity(value="EstadisticaDeVentas", noClassnameStored=true) 
public class SaleStatistics extends FactTableEntity { 

    @Embedded(value="Gasolinera", concreteClass=GasStationEmbedded.class) 
    private GasStationEmbedded gasStation; 

    @Embedded(value="Producto", concreteClass=ProductEmbedded.class) 
    private ProductEmbedded product; 

    @Embedded(value="Cliente", concreteClass=ClientEmbedded.class) 
    private ClientEmbedded client; 

    @Embedded(value="Turno", concreteClass=ShiftEmbedded.class) 
    private ShiftEmbedded shift; 

    @Embedded(value="Responsable", concreteClass=ResponsibleEmbedded.class) 
    private ResponsibleEmbedded responsible; 

    @Embedded(value="Isla", concreteClass=IslandEmbedded.class) 
    private IslandEmbedded island; 

    @Embedded(value="Vehiculo", concreteClass=VehicleEmbedded.class) 
    private VehicleEmbedded vehicle; 

    @Property("Origen") 
    private OriginType originType; 

    @Property("Canal") 
    private Channel channel; 

    @Property("Cantidad") 
    private BigDecimal quantity; 

    @Property("Jarreo") 
    private BigDecimal samplesQuantity; 

    @Property("Precio") 
    private BigDecimal price; 

    @Property("Monto") 
    private BigDecimal amount; 

    @Property("CostoDeVenta") 
    private BigDecimal costAmount; 

    public OriginType getOriginType() { 
     return originType; 
    } 
    public void setOriginType(OriginType originType) { 
     this.originType = originType; 
    } 

    public BigDecimal getQuantity() { 
     return quantity; 
    } 
    public void setQuantity(BigDecimal quantity) { 
     this.quantity = quantity; 
    } 

    public BigDecimal getSamplesQuantity() { 
     return samplesQuantity; 
    } 
    public void setSamplesQuantity(BigDecimal samplesQuantity) { 
     this.samplesQuantity = samplesQuantity; 
    } 

    public BigDecimal getPrice() { 
     return price; 
    } 
    public void setPrice(BigDecimal price) { 
     this.price = price; 
    } 

    public BigDecimal getAmount() { 
     return amount; 
    } 
    public void setAmount(BigDecimal amount) { 
     this.amount = amount; 
    } 


    public BigDecimal getCostAmount() { 
     return costAmount; 
    } 
    public void setCostAmount(BigDecimal costAmount) { 
     this.costAmount = costAmount; 
    } 

    public Channel getChannel() { 
     return channel; 
    } 
    public void setChannel(Channel channel) { 
     this.channel = channel; 
    } 
    public GasStationEmbedded getGasStation() { 
     return gasStation; 
    } 
    public void setGasStation(GasStationEmbedded gasStation) { 
     this.gasStation = gasStation; 
    } 
    public ProductEmbedded getProduct() { 
     return product; 
    } 
    public void setProduct(ProductEmbedded product) { 
     this.product = product; 
    } 
    public ClientEmbedded getClient() { 
     return client; 
    } 
    public void setClient(ClientEmbedded client) { 
     this.client = client; 
    } 
    public ShiftEmbedded getShift() { 
     return shift; 
    } 
    public void setShift(ShiftEmbedded shift) { 
     this.shift = shift; 
    } 
    public ResponsibleEmbedded getResponsible() { 
     return responsible; 
    } 
    public void setResponsible(ResponsibleEmbedded responsible) { 
     this.responsible = responsible; 
    } 
    public IslandEmbedded getIsland() { 
     return island; 
    } 
    public void setIsland(IslandEmbedded island) { 
     this.island = island; 
    } 
    public VehicleEmbedded getVehicle() { 
     return vehicle; 
    } 
    public void setVehicle(VehicleEmbedded vehicle) { 
     this.vehicle = vehicle; 
    } 


} 

Und Hier ist mein Product Entity Mapping:

public class Product { 

    @Property("Codigo") 
    private Integer code; 

    @Property("Denominacion") 
    private String description; 

    @Property("UnidadDeMedida") 
    private String messureUnit; 

    @Property("Departamento") 
    private String store; 

    @Property("Familia") 
    private String productFamily; 

    @Property("SubFamilia") 
    private String productSubFamily; 

    @Property("ClaveProveedor") 
    private String providerCode; 

    public Integer getCode() { 
     return code; 
    } 
    public void setCode(Integer code) { 
     this.code = code; 
    } 

    public String getDescription() { 
     return description; 
    } 
    public void setDescription(String description) { 
     this.description = description; 
    } 

    public String getMessureUnit() { 
     return messureUnit; 
    } 
    public void setMessureUnit(String messureUnit) { 
     this.messureUnit = messureUnit; 
    } 

    public String getStore() { 
     return store; 
    } 
    public void setStore(String store) { 
     this.store = store; 
    } 

    public String getProductFamily() { 
     return productFamily; 
    } 
    public void setProductFamily(String productFamily) { 
     this.productFamily = productFamily; 
    } 

    public String getProductSubFamily() { 
     return productSubFamily; 
    } 
    public void setProductSubFamily(String productSubFamily) { 
     this.productSubFamily = productSubFamily; 
    } 

    protected String getProviderCode() { 
     return providerCode; 
    } 
    protected void setProviderCode(String providerCode) { 
     this.providerCode = providerCode; 
    } 



} 

@Embedded 
public class ProductEmbedded extends Product { 

} 

Mache ich etwas falsch?

Antwort

0

Die Form der Dokumente kann zu diesem Zeitpunkt nicht garantiert werden, daher gibt es kein echtes Java-Modell, für das eine Validierung durchgeführt werden soll. Es ist zwar nicht ideal, um sicher zu sein, aber wir arbeiten an einer Lösung für die Verfolgung der Dokument-/Modelländerung durch verschiedene Pipeline-Phasen.

+0

Aber wenn Aggregation wurde auf SaleStatistics.class getan und Eigenschaften gruppiert sind aus dem eingebetteten Dokument sehe ich nicht, warum Sie nicht können. Dies macht die Kombination von Mapping und Aggregation nutzlos imho –

+0

Eine $ Gruppe könnte nach einem $ Projekt, z.B. und mehrmals in einer gegebenen Pipeline. Es gibt einfach keine Möglichkeit zu garantieren, dass die Dokumentform zu diesem Zeitpunkt mit irgendeinem Java-Typ übereinstimmt. – evanchooly