in a message driven bean i persist entries to lookup-table with unique entries. Basicly i create a select statement with the criteria api and if i don't find an entry, i create one.
Currently this code is running into mysql errors because in certain cases this entry creation (em.persist(entry)
) would violate the unique constrain on my database. another instance of my mdb created the lookup entry after i didn't find it and before i could create it.
How can i handle this synchronization problem, so there still is only one entry?