I have a swt client and a stateless facade that expose the server API to the client.
Suppose that I have two objects - Company the contain list of workers
I want to write a generic API to the client that create,add,update,delete objects.
Some objects, like worker need to be created in a parent context.
I mean that in order to create new worker we need to have the company that the worker belongs.
So, I thought about the following API:
Object public createObj(parentId,parentType,obj);
The function will add the worker to the list of workers in company and will return the new Worker object (with the ID).
There are some issues here:
1. In order to save the new worker I need to get the workers list in company than add the new worker and save the company.
The problem is that in case that there are thousands of workers we will need to load all the workers for only save one worker.
2. hibernate required to save the company object in order to save the worker (there are OneToMany), so the persist return Company object but i want to return to the client the new Worker that has been created.
I don't want to run on all the thousands of workers in order to search this worker.
How you overcome the problem that I mention above?