[jboss-user] [EJB 3.0] - Re: deleted entity passed to persist exception ???

nonreva do-not-reply at jboss.com
Wed Aug 20 23:21:20 EDT 2008


With Jboss 4.2.2GA I am experiencing a similar problem.

The gist of it is (within a single container managed transaction):
1. I remove an item from this collection...

  |     @OneToMany(mappedBy = "ivrAccount", cascade = CascadeType.ALL)
  |     public Collection<LinkedAccountBean> linkedAccounts = new HashSet<LinkedAccountBean>();
2. I perform a query on another bean...


  |             try {
  |                 System.out.println("************ 1 **************");
  |                 String number = accountReference.getNumber();
  |                 System.out.println("************ 2 ************** " + number);
  | 
  |                 Query q= em.createNamedQuery(
  |                         BankAccountReference.FIND_BY_ACCOUNT_NUMBER_QUERY)
  |                         .setParameter("number", number);
  |                 System.out.println("************ 3a **************");
  |                 Object o = q.getSingleResult();
  |                 System.out.println("************ 3b **************");
  |                 linkedAccount.accountReference = (BankAccountReference) o;
  |                 System.out.println("************ 3c **************");
  | 
  |             } catch (NoResultException ex) {
  |                 System.out.println("************ 4 **************");
  |                 linkedAccount.accountReference = BankAccountReferenceHelper
  |                         .createBankAccountReference(em, accountReference);
  |             } catch (EntityNotFoundException ex) {
  |                 System.out.println("************ XXXXX  **************");
  |                 throw ex;
  |             }
  | 
This results in an EntityNotFoundException...

  | 14:29:51,593 ERROR [STDERR] Caused by: javax.persistence.EntityNotFoundException: deleted entity passed to persist: [ae.
  | hilal.j2ee.entity.account.LinkedAccountBean#<null>]
  | 14:29:51,593 ERROR [STDERR]     at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityM
  | anagerImpl.java:613)
  | 14:29:51,593 ERROR [STDERR]     at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:99)
  | 14:29:51,593 ERROR [STDERR]     at ae.hilal.j2ee.session.helper.LinkedAccountHelper.update(LinkedAccountHelper.java:40)
  | 14:29:51,593 ERROR [STDERR]     at ae.hilal.j2ee.session.helper.LinkedAccountHelper.createLinkedAccount(LinkedAccountHel
  | per.java:123)
  | 
This can be seenn from the following output:
16:40:02,156 INFO  [STDOUT] ************ 1 **************
  | 16:40:02,156 INFO  [STDOUT] ************ 2 ************** 4444444444
  | 16:40:02,156 INFO  [STDOUT] ************ 3a **************
  | 16:40:02,156 INFO  [STDOUT] ************ XXXXX  **************

this appears to me to be the cause of a 
anonymous wrote : 14:29:51,593 ERROR [STDERR] javax.ejb.EJBTransactionRolledbackException: deleted entity passed to persist: [ae.hilal.j2e
  | e.entity.account.LinkedAccountBean#]
  | 14:29:51,593 ERROR [STDERR]     at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:87)
  | ...

What is ironic about this is that if I do the remove after the query it works... i.e. I collect up the objects that need to be removed and I remove them after I have done additions and updates to the collection.

Whilst this workaround appears to solve the problem in this particular instance, there is only an indirect relationship between the object deleted and the query. Furthuermore I am not convinced that if further queries were to follow the delete (untested scenarios) that these might also lead to problemd.

The EJB persistence specification (A.4) says that 
anonymous wrote : Replaced EntityNotFoundException with NoResultException in
  | entities might be returned, and exception should be recoverable., so I am also wondering why such an exception is still being propagated from a query (if my understanding of the stack trace is correct)

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4171657#4171657

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4171657



More information about the jboss-user mailing list