-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: hibernate cascade delete fails
PostPosted: Sat May 02, 2009 7:40 pm 
Newbie

Joined: Sat May 02, 2009 7:18 pm
Posts: 2
Hello people,

Having a problem with Hibernate, and i can't figure it out. Please help...
Exception stack trace :
Code:
04:54:54,093 ERROR [STDERR] org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [entities.Contacte#7]
        at org.hibernate.engine.StatefulPersistenceContext.checkUniqueness(StatefulPersistenceContext.java:590)
        at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:99)
        at org.hibernate.impl.SessionImpl.fireDelete(SessionImpl.java:775)
        at org.hibernate.impl.SessionImpl.delete(SessionImpl.java:758)
        at org.hibernate.engine.CascadingAction$1.cascade(CascadingAction.java:121)
        at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:268)
        at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:216)
        at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
        at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
        at org.hibernate.event.def.DefaultDeleteEventListener.cascadeAfterDelete(DefaultDeleteEventListener.java:327)
        at org.hibernate.event.def.DefaultDeleteEventListener.deleteEntity(DefaultDeleteEventListener.java:266)
        at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:141)
        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:357)
        at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performUpdate(DefaultSaveOrUpdateEventListener.java:329)
        at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsDetached(DefaultSaveOrUpdateEventListener.java:223)
        at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:89)
        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 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
        at $Proxy75.saveOrUpdate(Unknown Source)
        at dbhelper.ServiceGeneral.salveazaObiect(ServiceGeneral.java:251)




Explanation : this exception is thrown when i am trying to delete an entity from a list.

Hierarchy is as follows :
Main entity i am calling Session.saveOrUpdate upon is called OperatoriInterni. This entity has a set of entities of type LocatiiOperatori - these are the ones i am trying to delete : i remove one LocatiiOperatori from the set, and then call saveOrUpdate upon OperatoriInterni. Strangely, problem doesn't appear on the removal of LocatiiOperatori entity, but rather on a child of LocatiiOperator (each LocatiiOperator has one Contacte - this is the entity involved in the exception above)

My mappings are as follows :

Class OperatoriInterni :

Code:
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER, mappedBy="operatoriInterni")
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
    public Set<LocatiiOperator> getLocatiiOperators() {
        return this.locatiiOperators;
    }


Class LocatiiOperator :

Code:
@ManyToOne(fetch=FetchType.EAGER, cascade=CascadeType.ALL)
@JoinColumn(name="CONTACTE_ID", nullable=false)
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.DELETE_ORPHAN})


callind code :

Code:
    public static void salveazaObiect(Object o) throws HibernateException {
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        try {
            session.saveOrUpdate(o);
            session.getTransaction().commit();
        } catch (HibernateException ex) {
            session.getTransaction().rollback();
            throw ex;
        }
    }

    .............

    ServiceGeneral.salveazaObiect(operatorIntern);

    .............



Does anyone have any idea on what i may be doing wrong here ? I am just trying to delete something, this should work...
Found something similar here :
viewtopic.php?p=2387041
...but this doesn't seem to help.

Any opinion is appreciated :)
Andrei


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.