I currently have a single entry point (through a @WebService) that manages a list of request, each of them being a DAO operation (ie createEmployee, createCompany, etc…).
A Company has multiple employees and when my list of commands is the following:
client call #1:
1. createCompany
2. createEmployee
3. addEmployeeToCompany
client call #2:
1. findAllCompanies
I get all the companies, but not the employees associated to them.
If i redeploy the app, and to the findAllCompanies command i comes with all the info (company + employees), seems some persistence bug.
All my beans are stateless (should they be statefull?) and my entity manager is injected on them (should it be only injected on the webservice bean and passed to the others?
The problem was due to JPA’s cache.
the query worked fine the first time, and all the subsequent queries feed themselves from the cache.
oracle docs had the answer, and this can be configured on multiple ways:
shared-cache-mode)javax.persistence.cache.retrieveModeandjavax.persistence.cache.storeModejavax.persistence.cache.retrieveModeandjavax.persistence.cache.storeModeon EntityManager’s find or refresh