[jboss-user] [EJB 3.0] - Merge a removed entity bean

sebciar do-not-reply at jboss.com
Fri Sep 1 05:15:23 EDT 2006


Hello,

I've a problem concerning merge entity bean (EJB3).
I use a session bean stateless with transactions that is able to create, update and remove an entity bean.
I've created a java client application that uses my session bean.


  | @TransactionAttribute(value=TransactionAttributeType.REQUIRES_NEW)
  | public void save(Object obj){
  | 		em.merge(obj);
  | 	}
  | 
  | @TransactionAttribute(TransactionAttributeType.REQUIRED)
  | public void removeAccessControl(Object obj) throws SecurityException{
  | 		AccessControl access=null;
  | 		access=em.find(AccessControl.class,accessControlid);
  | 
  | 		//Remove dependecies
  | 		em.remove(access);
  | 	}
  | 

I run two instances of my client to simulate two users actions. The first one tries to remove the the entity #1 and the second client tries to rename same data row(#1).The Remove action is run just before the update.
The remove action deletes my bean in my database. But I was expecting that my update will fail (I use me.merge(obj)). NO! The row is added with a new ID: #2.
All entity object passed in parameters in my methods are detached.

Is that behavior normal? Is it possible, in my case, to make the entity manager automatically crache when I try to merge an entity which has been deleted by another thread without making a database check in my code ?

I tried the following code in my session bean : 

  | public void test(){
  | 	em.remove(entity);
  | 	/*....*/
  | 	em.merge(entity);
  | }
  | 
Here an exception is thrown that informs me that entity manager cannot merge a deleted entity. I would like to have the same behavior between 2 different transactions and 2 different threads...

Thank fo all help answers.

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

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



More information about the jboss-user mailing list