0

We are using EJB 2.1 with container managed persistence in IBM Websphere 8 and have the following problem: A single Object finder sometimes return 2 elements even though there is only one element the database for this search criteria. This happens only while many threads are accessing the same database entry.

We are using wsOptimisticUpdate as Access Intent. Inside the transaction the element is first searched using the business key (this the single object finder, which sometimes finds 2 elements and therefore throws an exception) and then updated. If many threads are doing this for the same business key, then this error occours.

Using a breakpoint for this exception and checking with uncommitted read on the database, it can be seen that there is only one element in database. So it looks like the CMP implementation is not really thread safe. Has anyone encountered such a problem before?

Caused by: javax.ejb.FinderException: Single object finder returned 2 objects.
    at
com.ibm.ws.ejbpersistence.beanextensions.ConcreteBeanStatefulInstanceExtensionImpl.executeFind(ConcreteBeanStatefulInstanceExtensionImpl.java:1579)
    at
ollo
  • 24,797
  • 14
  • 106
  • 155

1 Answers1

0

I'm no expert on CMP finders, but it may be due to the EJB QL predefined query not including a DISTINCT keyword in your SELECT clause. i.e.

SELECT **DISTINCT** OBJECT(o) FROM YourEntity AS o WHERE o.id = ?1;

(without the astericks)

coderatchet
  • 8,120
  • 17
  • 69
  • 125