I am using batch processing to persist my data by using flush() and clear() every few hundred records.
I have a query that looks up records to determine if I am doing an insert or update:
Code:
Query findQuery = entityManager.createNamedQuery(Constants.NAMED_QUERY_BLS_MAIN_FIND_BY_PIN);
findQuery.setParameter(1, pin);
return (BlsMain) findQuery.getSingleResult();
If I find a record I know it is an insert. The problem is that if in the same batch I save() two records who have a unique PIN the query above does not return a row unless the batch has been flushed already. By turning off batching it works fine since the query will find the already persisted object.
hibernate properties:
Code:
hibernate.jdbc.batch_size 100
hibernate.cache.use_second_level_cache false
hibernate.order_inserts=true
hibernate.order_updates=true
My question is how do I query the entity manager in such a way that I am potentially querying for objects that have not been persisted yet?
Thanks in advance.
Franz Garsombke