I am developping a JPA application (with hibernate), and I am fighting with the AutoFlush feature.
By default, whenever we process a query on any entity, the complete EntityManager is flushed. This is ok in most cases : We want JPA to process queries against an up-to-date DB.
However, it happens that we also store some functional parameters in our DB. This is completely separated from our core business model, and we don't want that selecting parameters we flushed the EM : Fetch of parameters can happen quite deep in the process and we loose the control of flushing EM when we know it;as ok.
Indeed, this causes some DB constraint exception : The data model is not consistent yet (in the middle of a process), and selecting a parameter forces the flush of this data model.
I am considering adding a second entityManager, just of the parameters, but I find it a bit overkill.
Could it be solved more easily ? With isolation level on the Parameters DAO, so that Parameters are processed in a separate transaction ?