As Pinaki pointed out, the following line -
if (!jpaEm.isDetached(found)) throw new
IllegalStateException("entity should be detached");
should be -
if (!jpaEm.isDetached(detached)) throw new
IllegalStateException("entity should be detached");
In OpenJPA 1.x, the original entity is not detached. The detach()
method returns a copy of the entity, which is detached. These detach
methods/behaviors are OpenJPA unique and were not in the JPA 1.0 Spec.
In OpenJPA 2.0, the original entity is detached in-place and no copy is
returned, as required by the JPA 2.0 Spec.
-Donald
On 3/17/10 2:19 PM, ubiteck wrote:
>
> According to the test case your send to me i wrote the following method
> without success :
>
> @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
> public Company getTestCompany(long id) {
>
> OpenJPAEntityManager jpaEm = OpenJPAPersistence.cast(em);
> jpaEm.clear();
>
> Company found = jpaEm.find(Company.class, id);
> if (!jpaEm.contains(found)) throw new
> IllegalStateException("entity not in
> manager!");
> if (jpaEm.isDetached(found)) throw new
> IllegalStateException("entity
> should not be detached yet");
> logger.info("Detaching...");
> Company detached = jpaEm.detach(found);
> logger.info("Detaching...done ");
> if (!jpaEm.isDetached(found)) throw new
> IllegalStateException("entity
> should be detached");
> return detached;
> }
>
>
> It throws an exception "entity shoul be detached". The return value
> (detached) is not considered as detached !
>
>
>