How to change entity , passed to the service bean?

Hello, sorry for may be this stupid question.

I am writing Screen Controller, where some button invokes some method.
In this method I am using getItem(), then change it (like .setSomeValue()) and those changes automatically reflects to database, so it’s ok;

But when I pass this object to ServiceBean, and modify it - nothing happens.

What is correct way to change the Entity form ServiceBean method?

public class OrganizationEdit extends AbstractEditor<Organization> {

    @Inject
    private QueryOrganizationDatabaseService queryOrganizationDatabaseService;

    public void onQueryClick() {

        Organization org = getItem();
        org.setNameShort("org"); // ok

        queryOrganizationDatabaseService.queryOrganization(org); // nothing happens
    }
}
@Service(QueryOrganizationDatabaseService.NAME)
public class QueryOrganizationDatabaseServiceBean implements QueryOrganizationDatabaseService {

    @Override
    public void queryOrganization(Organization org) {
        org.setNameShort("org2"); // this call does not change entity
    }
}

Hi,
When you invoke a service from a screen controller, you pass parameters and results between application tiers - client and middleware. In this case the data is serialized and deserialized, which means parameters are passed “by value”. The only way to return something to the caller is to return a result. You could easily return the changed instance:

@Service(QueryOrganizationDatabaseService.NAME)
public class QueryOrganizationDatabaseServiceBean implements QueryOrganizationDatabaseService {

    @Override
    public Organization queryOrganization(Organization org) {
        org.setNameShort("org2");
        return org;
    }
}

But in this case you have to set it back to the screen’s datasource:

Organization changedOrg = queryOrganizationDatabaseService.queryOrganization(org);
organizationDs.setItem(changedOrg);

Consider also returning a value object and updating attributes of the entity on the client side separately. Then you don’t need to re-set it in the datasource.

Кстати, это русскоязычный форум и здесь лучше писать на русском. Я поздно это заметил.

Спасибо. Да, я остановился на возвращении value object. Потому что вариант предложенный Вами почему то не работал, проверю еще раз. Зато работал вариант, когда в сервисе делаем

  
@Override 
public Organization queryOrganization(Organization org) { 
    org2 = new Organization(); 
    org2.setNameShort("org2"); 
    return org2; 
}

А вот почему то возврат измененного org не работал.
Еще тогда не подскажете - правильный способ присвоить один entity другому? clone() вроде нету

Можно скопировать состояние: см. методы copy(), deepCopy() в MetadataTools.