EJB 3.0 entity manager persis() in case of duplication

Discussions

EJB programming & troubleshooting: EJB 3.0 entity manager persis() in case of duplication

  1. Hello, I've a problem with the entity manager of EJB3.0. In fact, I've a business method in a session bean who adds simply several records into 5 entity beans. And the business logic requires that it be in one transaction, either success to add them all, or I rollback. The trouble is the following : I've several concurrent client of this business session bean. They can call simultanously the business method to add records. And in many cases, some records of some entity can be duplicated. And I want just to bypass the creation if the record exists already. But with the em.persist(), if the record exists, an EntityExistsException is thrown and the transaction is automatally rollbacked (however I want to continue, just discard the creation of the duplicated record, but I should continue to create other records). I think it's a relatively common problem one can meet. But after searching on Google, I've not found a good answer. How do you think about it? Maybe there's something wrong in my conception? Thanks in advance for your help.
  2. I am assuming u are using container managed transaction. One obvious answer is use bean managed transaction and handle the rollback conditionally....Data Stomping or versioning is the issue that you are hitting upon.. which is still a lingering issue in EJB3 Bhagvan K http://www.jroller.com/page/bhagvank