Hi To retrieve Child Entity Details From Parent Entity

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Hi To retrieve Child Entity Details From Parent Entity

reddyraja86
Hi All,
I am new to ofbiz ,I have a requirement where i am retrieving Products and product categories , i have product category id.I can get the ProductCategory details but i am not able to retrieve the Product details.(Productcategory and Product are two entities they have one to many relation)

My Code is

GenericDelegator delegator = (GenericDelegator) DelegatorFactory.getDelegator("default");
GenericValue  agreementItems=delegator.findByPrimaryKeyCache("ProductCategory", UtilMisc.toMap("productCategoryId", request.getParameter("id")));
System.out.println( agreementItems.getString("categoryName"));

But i am not able to get the product details

List l=(List)agreementItems.getRelatedCache("primaryProducts");

can anyone help me.

Reply | Threaded
Open this post in threaded view
|

Re: Hi To retrieve Child Entity Details From Parent Entity

Paul Foxworthy
Hi Reddy,

You want just "Product" not "primaryProducts". getRelated expects the name of the related entity. One way of finding related entities is to look in the Web Tools. For example, see

https://demo-trunk.ofbiz.apache.org/webtools/control/ViewRelations?entityName=ProductCategory

(or the equivalent in your own deployment of Ofbiz) for the exact names of the entities related to ProductCategory.

Cheers

Paul Foxworthy

reddyraja86 wrote
Hi All,
I am new to ofbiz ,I have a requirement where i am retrieving Products and product categories , i have product category id.I can get the ProductCategory details but i am not able to retrieve the Product details.(Productcategory and Product are two entities they have one to many relation)

My Code is

GenericDelegator delegator = (GenericDelegator) DelegatorFactory.getDelegator("default");
GenericValue  agreementItems=delegator.findByPrimaryKeyCache("ProductCategory", UtilMisc.toMap("productCategoryId", request.getParameter("id")));
System.out.println( agreementItems.getString("categoryName"));

But i am not able to get the product details

List l=(List)agreementItems.getRelatedCache("primaryProducts");

can anyone help me.
--
Coherent Software Australia Pty Ltd
http://www.coherentsoftware.com.au/

Bonsai ERP, the all-inclusive ERP system
http://www.bonsaierp.com.au/