0

I have a scenario where i have to fine multiple queries to get the result. Since EntityView is interface and if i want to send API response with some custom attributes that is not defined in Entity, how can i do that?

@EntityView(DealListing.class)
public abstract class DealListingBuyerView {
abstract Long getId();

abstract Long getDealTypeId();

abstract DealRelatedType getDealRelatedType();

abstract String getRelatedCode();

abstract DealStatus getDealListingStatus();

abstract String getDealListingCompletionRate();

abstract DealRefDataBuyerView getDealRefData();
}

The last attribute DealRefDataBuyerView is not a field in the Entity

Mayuran
  • 669
  • 2
  • 8
  • 39

1 Answers1

1

I don't know where the value comes from, so I can only guess. You have various mapping annotations that you can use to access values or use expressions to model what you need like e.g. @Mapping. See the documentation for more details. Here is an example where you would join the data based on some custom join condition DealRef.deal.id = DealListing.id:

@EntityView(DealListing.class)
public interface DealListingBuyerView {

    @IdMapping
    Long getId();
    Long getDealTypeId();
    DealRelatedType getDealRelatedType();
    String getRelatedCode();
    DealStatus getDealListingStatus();
    String getDealListingCompletionRate();

    @Mapping("DealRef[deal.id = VIEW(id)]")
    DealRefDataBuyerView getDealRefData();
}
Christian Beikov
  • 15,141
  • 2
  • 32
  • 58
  • 1
    Thanks for the suggestion, I have made the view abstract class instead of interface and added new custom fields, so that i can set any other fields as i wish. I will read more about @Mapping, it seems quite powerful – Mayuran Sep 10 '21 at 00:58