0

There are 3 tables in my db:

SalesOrderMaster
SalesOrderDetail
CustomerMaster

I have repository class SalesOrderDetailRespository.java which has this method findAll()

@EntityGraph(attributePaths = {"SalesOrderMaster"}, type = EntityGraph.EntityGraphType.FETCH)
List<SalesOrderInfo> findAll(@Nullable Specification<SalesOrderInfo> spec);

This is till now fetching the SalesOrderMaster record and associated SalesOrderDetails records. Now my requirement is in SalesOrderInfo class , I have added a new property for showing the Customer Information like Name , country which are there in CustomerMaster table.

The customerMaster table is related to SalesOrderMaster by customerId column. How do I add CustomerMaster table in the existing EntityGraph so that I can get this info?

halfer
  • 19,824
  • 17
  • 99
  • 186
CrazyCoder
  • 2,194
  • 10
  • 44
  • 91
  • 1
    You can specify an attribute path to that `attributePaths = {"SalesOrderMaster", "SalesOrderMaster.nameOfPropertyInSalesOrderMaster"}` – Daniel Rafael Wosch Jun 07 '21 at 12:57
  • @DanielWosch , I tried. it is not working – CrazyCoder Jun 07 '21 at 13:24
  • But I understand you correctly that SalesOrderMaster contains a property representing the CustomerMaster? – Daniel Rafael Wosch Jun 07 '21 at 13:26
  • @DanielWosch yes. Do I need to add that some where in the entity graph declaration? – CrazyCoder Jun 07 '21 at 13:28
  • Sure, that what I was talking about. Sorry :) For example: `@EntityGraph(attributePaths = {"basket", "payment", "payment.history", "invoiceAddress"}, type = EntityGraph.EntityGraphType.LOAD) List findAll()` => This fetches all `PurchesOrderEntites`with the named properties of the entity. PurchaseOrderEntity has a property called payment and payment has a property history => `payment.history` in entity graph – Daniel Rafael Wosch Jun 07 '21 at 13:35
  • 1
    @DanielWosch I have in a similar way as you mentioned. Still it is not working. I have raised another question with the exact error message and how the named entity graph is defined. Can you please have a look at it : https://stackoverflow.com/q/67882006/8930751 – CrazyCoder Jun 08 '21 at 05:43

0 Answers0