Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: IllegalArgumentException: Removing a detached instance
PostPosted: Tue Mar 27, 2007 11:12 am 
Newbie

Joined: Wed Jun 28, 2006 3:32 pm
Posts: 16
The test case at the bottom of the stack trace clears the member collection in SortContext and then persists the SortContext with a remote call to the JBoss server. When I use EntityManager.merge() to persist the SortContext, everything works fine. But I need to use Session.saveOrUpdate() (I get the Session from the EntityManager) and that gives me the exception below. How can I fix this?

Hibernate version: 3.2.0

Mapping documents:
Code:
@Entity
@Table(name = "SORT_CONTEXT")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "SORT_CONTEXT_TYPE", discriminatorType = DiscriminatorType.INTEGER)
@DiscriminatorValue("0")
public class SortContext extends PersistentDomainObject {
   
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SORT_CONTEXT_SEQ")
    @SequenceGenerator(name = "SORT_CONTEXT_SEQ", sequenceName = "SORT_CONTEXT_SEQ", allocationSize = 1)
    @Column(name = "SORT_CONTEXT_ID")
    private Long id;

    @OneToMany(cascade = {CascadeType.ALL }, mappedBy = "sortContext")
    @OrderBy("index")
    @Cascade({ org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
    private List<SortContextMember> members = new ArrayList<SortContextMember>();

}

@Entity
@Table(name = "SORT_CONTEXT_MEMBER")
public class SortContextMember extends PersistentDomainObject {
   
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SORT_CONTEXT_MEMBER_SEQ")
    @SequenceGenerator(name = "SORT_CONTEXT_MEMBER_SEQ", sequenceName = "SORT_CONTEXT_MEMBER_SEQ", allocationSize = 1)
    @Column(name = "SORT_CONTEXT_MEMBER_ID")
    private Long id;

    @ManyToOne(optional = false)
    @JoinColumn(name = "SORT_CONTEXT_ID", nullable = false)
    private SortContext sortContext;

    @Column(name = "MEMBER_INDEX", nullable = false)
    private int index;
   
    @Column(name = "IS_ASCENDING", nullable = false)
    private boolean ascending;

    @ManyToOne(optional = false)
    @JoinColumn(name = "SORT_ATTRIBUTE_ID", nullable = false)
    private SortAttribute sortAttribute;

}


Full stack trace of any exception that occurs:
Code:
javax.ejb.EJBException: java.lang.IllegalArgumentException: Removing a detached instance com.lggi.esp.domain.processing.catalog.SortContextMember#13
    at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:69)
    at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
    at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:197)
    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.RoleBasedAuthorizationInterceptor.invoke(RoleBasedAuthorizationInterceptor.java:167)
    at org.jboss.ejb3.security.RoleBasedAuthorizationInterceptor.invoke(RoleBasedAuthorizationInterceptor.java:108)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:78)
    at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:131)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
    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.dynamicInvoke(StatelessContainer.java:263)
    at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:106)
    at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
    at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:828)
    at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:681)
    at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:358)
    at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:412)
    at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:239)
Caused by: java.lang.IllegalArgumentException: Removing a detached instance com.lggi.esp.domain.processing.catalog.SortContextMember#13
    at org.hibernate.ejb.event.EJB3DeleteEventListener.performDetachedEntityDeletionCheck(EJB3DeleteEventListener.java:47)
    at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:75)
    at org.hibernate.impl.SessionImpl.fireDelete(SessionImpl.java:775)
    at org.hibernate.impl.SessionImpl.delete(SessionImpl.java:758)
    at org.hibernate.engine.Cascade.deleteOrphans(Cascade.java:355)
    at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:324)
    at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:242)
    at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:219)
    at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
    at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
    at org.hibernate.engine.Cascade.cascade(Cascade.java:97)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.cascadeOnUpdate(DefaultSaveOrUpdateEventListener.java:332)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performUpdate(DefaultSaveOrUpdateEventListener.java:304)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsDetached(DefaultSaveOrUpdateEventListener.java:217)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
    at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:507)
    at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:499)
    at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:495)
    at com.lggi.esp.services.ejb.persistence.PersistenceBean.persist_aroundBody12(PersistenceBean.java:116)
    at com.lggi.esp.services.ejb.persistence.PersistenceBean$AjcClosure13.run(PersistenceBean.java:1)
    at org.aspectj.runtime.reflect.JoinPointImpl.proceed(JoinPointImpl.java:101)
    at com.lggi.esp.services.aspects.security.SecurityAspect.aroundSecuredMethods(SecurityAspect.aj:150)
    at com.lggi.esp.services.ejb.persistence.PersistenceBean.persist(PersistenceBean.java:111)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
    at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
    at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
    at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:197)
    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.RoleBasedAuthorizationInterceptor.invoke(RoleBasedAuthorizationInterceptor.java:167)
    at org.jboss.ejb3.security.RoleBasedAuthorizationInterceptor.invoke(RoleBasedAuthorizationInterceptor.java:108)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:78)
    at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:131)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
    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.dynamicInvoke(StatelessContainer.java:263)
    at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:106)
    at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
    at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:828)
    at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:681)
    at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:358)
    at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:412)
    at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:239)
    at org.jboss.remoting.RemoteClientInvoker.invoke(RemoteClientInvoker.java:190)
    at org.jboss.remoting.Client.invoke(Client.java:525)
    at org.jboss.remoting.Client.invoke(Client.java:488)
    at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:55)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:61)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    at org.jboss.aspects.security.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:55)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:77)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:102)
    at $Proxy33.persist(Unknown Source)
    at com.lggi.esp.services.ejb.catalog.SortContextBeanTest.testSortContextMembers(SortContextBeanTest.java:109)


Name and version of the database you are using: Oracle 10.2.0


Top
 Profile  
 
 Post subject: Re: IllegalArgumentException: Removing a detached instance
PostPosted: Tue Feb 08, 2011 7:14 am 
Newbie

Joined: Tue Feb 08, 2011 7:12 am
Posts: 1
Hi, i have the same problem.
Did you found the solution?


Top
 Profile  
 
 Post subject: Re: IllegalArgumentException: Removing a detached instance
PostPosted: Tue Feb 08, 2011 12:47 pm 
Newbie

Joined: Wed Jun 28, 2006 3:32 pm
Posts: 16
This was so long ago, I don't remember. In general, I now avoid JPA and EntityManager because I don't see any benefits from using it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.