• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1519
  • Last Modified:

EJB 3 Deleting a Detached Instance

I'm trying to delete a detached instance. Where in the object is first converted to manage instance by first calling merge on it and then call remove.

The following exceptionis thrwon  when trying to call remove on the entity instance.

Server: JBOSS 4.2
EJB 3 Entity and SessionBeans.



@TransactionAttribute(TransactionAttributeType.REQUIRED)
	public void saveSelectedAccountAndGroupsList(ApplicationContext applicationContext,
			ArrayList<TabActiveAccounts> existingGroupList,
			AccountGroupList accountGroups) throws VoltsValidationException {
		
		for (int i = 0; i < existingGroupList.size(); i++) {
			TabActiveAccounts tabActiveAccount = existingGroupList.get(i);
			if (i + 1 <= VoltsConstants.MAX_ACCOUNTS) {
				em.merge(tabActiveAccount);
			} else {
				em.merge(tabActiveAccount);
				em.flush();
				em.remove(tabActiveAccount);
			}
		}
	}

Open in new window

0
dolphin_g
Asked:
dolphin_g
  • 3
  • 2
  • 2
1 Solution
 
ramazanyichCommented:
could you send stacktrace of your exception ?
0
 
dolphin_gAuthor Commented:
attached is the log.
2008-11-03 09:08:51,772 DEBUG [org.hibernate.jdbc.ConnectionManager] releasing JDBC connection [ (open PreparedStatements: 0, globally: 1) (open ResultSets: 0, globally: 0)]
2008-11-03 09:08:51,772 DEBUG [org.hibernate.jdbc.AbstractBatcher] about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2008-11-03 09:08:51,772 DEBUG [org.hibernate.jdbc.ConnectionManager] skipping aggressive-release due to flush cycle
2008-11-03 09:08:51,772 ERROR [org.hibernate.event.def.AbstractFlushingEventListener] Could not synchronize database state with session
org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.vantra.volts.core.po.TabActiveAccounts#45]
	at org.hibernate.persister.entity.AbstractEntityPersister.check(AbstractEntityPersister.java:1765)
	at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2407)
	at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2307)
	at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2607)
	at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:92)
	at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:142)
	at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
	at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
	at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
	at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
	at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:515)
	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:1382)
	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:76)
	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:106)
	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:214)
	at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:184)
	at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:81)
	at $Proxy428.saveSelectedAccountAndGroupsList(Unknown Source)

Open in new window

0
 
ramazanyichCommented:
Is your TabActiveAccounts  class referenced in some other ejb3 entity ?
and also from where do you call saveSelectedAccountAndGroupsList(): is it internal call inside your j2ee code ? or you do it call from client application ?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
dolphin_gAuthor Commented:
TabActiveAccounts is not referenced from other ejb3 entities. And, Yes, I do call saveSelectedAccountAndGroupsList() from my Struts Action client.

I have found a workaround for this:

TabActiveAccounts activeaccount = em.merge(tabActiveAccount);
em.remove(activeAccount);

Open in new window

0
 
Mr_ItCommented:
Did you specify a 'version' element in your hibernate mapping for the TabActiveAccounts class  and accidentally overwrite the value of  this property in your view client (or instantiate a new TabActiveAccounts object while leaving the version property uninitialized, defaulted '0' for an int)?

I can think of a scenario in which you copy all the properties of the bean to a struts form and the other way around, and that the value of the 'version' property is lost somewhere in the process.

Just debug and see what the version is in your object at runtime and in your database before you flush or commit the transaction. It should match.
0
 
dolphin_gAuthor Commented:
Sorry, I completely lost track of this question. Thank you.
0
 
Mr_ItCommented:
No problem. Thanks!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now