Java code for entity

0
Hi all, I have 2 Entities  as a picture, I would like to know java code to query all from table insert OutsourceName to entity by assosiation  delete or update data for entity   Anyone who can help me to guide me for java code.
asked
2 answers
0

Hi Somboon,

 

First of all, I would like to point you to the documentation here.

Now to answer your questions:

  1. You can use a XPath retrieve like this:
    XPath<IMendixObject> xpath = XPath.create(getContext(), EntitiyToRetrieve.getType());  // Use the proxie of your entity: moduleName.proxies.entityName.getType()
    List<IMendixObject> entityList =  xpath.allMendixObjects();

     

  2. Say you have an OutSourceName object named outSourceName and an OutSourceCompany object named outSourceCompany, you can set the association like so:  
    //Set the association:
    outSourceName.setValue(context, OutSourceName.MemberNames.outSourceName_outSourceCompany.toString(), outSourceCompany);
  3. You can commit or delete date using the commit() and delete() functions from the Core library. Please see the documentation for more details.
answered
0

Thanks , Lennert Sietsma

I will try your solutuion.

 

I do workaround with my code , it can retrive dataList and insert data to entity. Is a good solution or not ?

List<OutSourceCompany> outSourceCompanyList = OutSourceCompany.load(getContext(), "[id!=empty]");
		for(OutSourceCompany com: outSourceCompanyList){
			System.out.println(com.getCompanyName());
			company=com.getCompanyName();
			OutsourceName outsourceName =  new OutsourceName(getContext());
			outsourceName.setOutsourceName("monkey"+com.getCompanyId());
			outsourceName.setOutsourceTel("222"+com.getCompanyId());
			outsourceName.setOutsourceName_OutSourceCompany(com);
			outsourceName.commit();
		}

 

answered