-->
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: NonUniqueObjectException on cascade
PostPosted: Fri May 11, 2007 1:38 am 
Newbie

Joined: Mon Nov 03, 2003 1:07 am
Posts: 14
I am getting a NonUniqueObjectException when I try to delete or save an object.
While I know what this error means, I don't understand how this could be happening since my testcase only retrieves the object (by id) from hibernate, initializes the OneToMany, and deletes the object (and cascade delete the OneToMany) all using the same object and object glyph.

How would loading an object in hibernate get it confused where it would create a different instance of an object instead of reusing that same object?

Thanks for your help. It's my final cry at 1:30 am all alone in my basement trying to get this to work.
Phillip


Hibernate version: 3.2.1

Mapping documents:
In Domain.java
private Set<User> users = new HashSet<User>();

@OneToMany(mappedBy = "domain",cascade = { CascadeType.ALL,CascadeType.MERGE }, fetch = FetchType.LAZY)
@Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
public Set<User> getUsers() {
return users;
}

public void setUsers(Set<User> users) {
this.users = users;
}


In User.java:
@ManyToOne(cascade = { CascadeType.PERSIST })
@JoinColumn(nullable = false)
public Domain getDomain() {
return domain;
}
public void setDomain(Domain domain) {
this.domain = domain;
}
private Domain domain = null;


Code between sessionFactory.openSession() and session.close():

Using springframework

Debug level Hibernate log excerpt:
The generated SQL (show_sql=true):
01:00:38,359 DEBUG AbstractBatcher:476 - preparing statement
01:00:38,375 DEBUG LongType:80 - binding '1' to parameter: 1
01:00:38,375 DEBUG AbstractBatcher:374 - about to open ResultSet (open ResultSets: 0, globally: 0)
01:00:38,375 DEBUG Loader:1040 - result set contains (possibly empty) collection: [org.authsum.om.Group.groupCycles#1]
01:00:38,375 DEBUG CollectionLoadContext:84 - uninitialized collection: initializing
01:00:38,375 DEBUG Loader:682 - processing result set
01:00:38,375 DEBUG Loader:709 - done processing result set (0 rows)
01:00:38,375 DEBUG AbstractBatcher:381 - about to close ResultSet (open ResultSets: 1, globally: 1)
01:00:38,375 DEBUG AbstractBatcher:366 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
01:00:38,375 DEBUG AbstractBatcher:525 - closing statement
01:00:38,390 DEBUG Loader:839 - total objects hydrated: 0
01:00:38,390 DEBUG CollectionLoadContext:262 - 1 collections were found in result set for role: org.authsum.om.Group.groupCycles
01:00:38,390 DEBUG CollectionLoadContext:206 - collection fully initialized: [org.authsum.om.Group.groupCycles#1]
01:00:38,390 DEBUG CollectionLoadContext:272 - 1 collections initialized for role: org.authsum.om.Group.groupCycles
01:00:38,390 DEBUG StatefulPersistenceContext:748 - initializing non-lazy collections
01:00:38,390 DEBUG Loader:2001 - done loading collection
01:00:38,390 DEBUG DefaultInitializeCollectionEventListener:61 - collection initialized
01:00:38,390 DEBUG Cascade:306 - done cascade ACTION_DELETE for collection: org.authsum.om.Group.groupCycles
01:00:38,406 DEBUG Cascade:150 - done processing cascade ACTION_DELETE for: org.authsum.om.Group
01:00:38,406 DEBUG SessionImpl:1308 - setting cache mode to: GET
01:00:38,406 DEBUG SessionImpl:1308 - setting cache mode to: GET
01:00:38,406 DEBUG Cascade:115 - processing cascade ACTION_DELETE for: org.authsum.om.Group
01:00:38,406 DEBUG CascadingAction:119 - cascading to delete: org.authsum.om.Domain
01:00:38,406 DEBUG DefaultDeleteEventListener:108 - deleting a persistent instance
01:00:38,406 DEBUG DefaultDeleteEventListener:111 - object was already deleted
01:00:38,406 DEBUG Cascade:150 - done processing cascade ACTION_DELETE for: org.authsum.om.Group
01:00:38,406 DEBUG SessionImpl:1308 - setting cache mode to: GET
01:00:38,406 DEBUG Cascade:306 - done cascade ACTION_DELETE for collection: org.authsum.om.Domain.groups
01:00:38,421 DEBUG Cascade:317 - deleting orphans for collection: org.authsum.om.Domain.groups
01:00:38,421 DEBUG Cascade:327 - done deleting orphans for collection: org.authsum.om.Domain.groups
01:00:38,421 DEBUG Cascade:291 - cascade ACTION_DELETE for collection: org.authsum.om.Domain.secureObjectTypes
01:00:38,421 DEBUG Cascade:306 - done cascade ACTION_DELETE for collection: org.authsum.om.Domain.secureObjectTypes
01:00:38,421 DEBUG Cascade:317 - deleting orphans for collection: org.authsum.om.Domain.secureObjectTypes
01:00:38,421 DEBUG Cascade:327 - done deleting orphans for collection: org.authsum.om.Domain.secureObjectTypes
01:00:38,421 DEBUG Cascade:291 - cascade ACTION_DELETE for collection: org.authsum.om.Domain.users
01:00:38,421 DEBUG CascadingAction:119 - cascading to delete: org.authsum.om.User
01:00:38,421 DEBUG DefaultDeleteEventListener:65 - entity was not persistent in delete processing
01:00:38,437 DEBUG VersionValue:44 - version unsaved-value strategy UNDEFINED
org.springframework.orm.hibernate3.HibernateSystemException: a different object with the same identifier value was already associated with the session: [org.authsum.om.User#1]; nested exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [org.authsum.om.User#1]
Caused by: org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [org.authsum.om.User#1]
at org.hibernate.engine.StatefulPersistenceContext.checkUniqueness(StatefulPersistenceContext.java:556)


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.