[jboss-user] [EJB 3.0] - javax.persistence.EntityNotFoundException: deleted entity pa

misterpea do-not-reply at jboss.com
Tue Dec 16 02:16:22 EST 2008


Hi all,

I have trawled the net for 3 days now and none of the solutions seem to work for me, I hope someone here can help!!!

I have 2 entity beans:
Company
Employee

Where a company has n employees.

My Company bean looks something like:


  | @Entity
  | @Table(name = "company")
  | public class Company implements Serializable 
  | {
  | 	private static final long serialVersionUID = 1L;
  | 	
  | 	@Id
  | 	@Column(name = "company_id", 
  | 			nullable = false)
  | 	@GeneratedValue
  | 	private Integer id;
  | 	
  | 	@Column(name = "name", 
  | 			nullable = false, 
  | 			unique=true)
  | 	private String name;
  | 	
  | 	@OneToMany(cascade = CascadeType.ALL,
  | 			   mappedBy = "employee",
  | 			   fetch = FetchType.EAGER)
  | 	private Set<Employee> employees;
  | 

My Employee bean looks something like:


  | @Entity   
  | @Table(name="employee")
  | public class Employee implements Serializable 
  | {
  | 	private static final long serialVersionUID = 1L;
  | 	
  | 	@Id
  | 	@Column(name = "employee_id", 
  | 			nullable = false)
  | 	@GeneratedValue
  | 	private Integer id;
  | 	
  | 	@ManyToOne
  | 	@JoinColumn(name="company_id", 
  | 				referencedColumnName="company_id", 
  | 				nullable=true)
  | 	private Company company;
  | 

Along with the getters, setters, hashCode, equals and toString methods.

When I try to delete an employee, I get the following error:


2008-12-16 17:31:06,942 WARN  [com.arjuna.ats.arjuna.logging.arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator_2] TwoPhaseCoordinator.beforeCompletion - failed for com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple at 1c67f50
javax.persistence.EntityNotFoundException: deleted entity passed to persist: [com.pea.myproject.ejb.entities.Employee#]
	at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:613)
	at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:524)
	at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:114)
	at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:247)
	at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:86)
	at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:177)
	at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1389)
	at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:135)
	at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:87)
	at org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:175)
	at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:87)
	at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
	at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95)
	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
	at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
	at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
	at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:110)
	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
	at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
	at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
	at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:240)
	at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:210)
	at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:84)


My remove code looks like this:


  | @PersistenceContext
  | protected transient EntityManager manager;
  | 
  | public void removeEmployee(final Employee employee) {
  |   Employee empEntity = manager.find(employee.getClass(), employee.getId());
  | 
  |   if(empEntity != null) {
  |     manager.remove(empEntity);
  |   }
  | 
  | 

Funny thing is the error occurs STRAIGHT AFTER this method gets called (and no further). This doesn't mean the remove(...) was successful because the entry is still there in the database.

I even print out empEntity.toString() before calling remove(...) to make sure it contains all the values I'm expecting it to contain.

I'm at a dead end ... I hope someone can shed some light to this issue!

Thanks!
pea

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

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



More information about the jboss-user mailing list