[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-3843) @Audited and @ManyToMany relation problem - after modyfing an Entity: org.hibernate.NonUniqueObjectException with message: "a different object with the same identifier value was already associated with the session ...

Nguyen (JIRA) noreply at atlassian.com
Fri Dec 11 14:40:08 EST 2009


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-3843?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=34932#action_34932 ] 

Nguyen commented on HHH-3843:
-----------------------------

Hello, 

Im having the same problem after exploring a bit i think i may give some hints on whats going on.
Problem comes when updating a relation that was already populate with some elements.
On a ManyToMany relation (and maybe some other relation too) the update is handle by removing all elements then adding all the new contents.
Because of the propagation of the elementary changes, Envers has to register in the same revision both a delete and a add for elements that were simply maintain in that relation and this is the trouble source.

Hope it may help...

Rémi

> @Audited and @ManyToMany relation problem - after modyfing an Entity: org.hibernate.NonUniqueObjectException with message: "a different object with the same identifier value was already associated with the session ...
> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HHH-3843
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3843
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: envers
>    Affects Versions: 3.3.1
>         Environment:  envers.jar 1.2.0, Hibernate 3.3.1, postgresql-8.3, jboss-4.2.3
>            Reporter: Michał Maryniak
>         Attachments: enverse.7z, enverse.zip
>
>
> There is a problem with unidirectional @ManyToMany relation. 
> This case is different than the one with inheritance: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3830.
> The example is trival and code is as simple as it can be.
> A single Person can have many roles, and one Role can by assigned to many Person entities.
> @Entity
> @Audited
> public class Person implements Serializable {
> (...)
> @ManyToMany
> 	public List<Role> getRoles() {
> 		return roles;
> 	}
> (...)
> }
> and
> @Entity
> @Audited
> public class Role implements Serializable {
> (...)
> }
> And here comes a use case:
> 1) I create role 'admin'
> 2) I create role 'user'
> 3) I create person 'john' and add him a role 'admin'
> 4) I edit 'john' and add him second role 'user'
> and I got an exception:
> org.hibernate.NonUniqueObjectException with message: "a different object with the same identifier value was already associated with the session: [Person_Role_AUD#{roles_id=1, Person_id=5, REV=DefaultRevisionEntity(id = 7, revisionDate = 2009-04-01 10:46:32)}]"
> If I add one role and remove the second one, or if I only remove a role - an Exception does not occur.
> I attached a zip file with this simple SEAM project generated by seam-gen 2.1.1 GA.
> I haven't included jar files, but project requires jar's "generated" with seam-gen (2.1.1) and following jar's have been replaced with new ones:
> 2008-06-13  13:09           313˙898 dom4j.jar								 	1.6.1
> 2009-03-23  13:01           285˙158 envers.jar									1.2.0-hibernate-3.3
> 2008-08-20  11:27           279˙714 hibernate-annotations.jar					3.4.0.GA
> 2008-08-20  11:31            66˙993 hibernate-commons-annotations.jar			3.1.0.GA
> 2008-08-20  12:19           119˙292 hibernate-entitymanager.jar					3.4.0.GA
> 2008-12-04  14:39           304˙236 hibernate-search.jar						3.1.0.GA
> 2008-09-10  14:01            62˙574 hibernate-validator.jar						3.1.0.GA
> 2008-09-10  13:27         2˙766˙130 hibernate.jar								from hibernate-distribution-3.3.1.GA-dist
> 2008-06-13  13:09            13˙236 jta.jar										1.1 (from hibernate-distribution-3.3.1.GA-dist)
> 2008-12-04  14:41           818˙961 lucene-core.jar								2.4.0 701827 - 2008-10-05 16:44:37
> 2008-08-19  20:40            17˙384 slf4j-api.jar								1.5.2
> If you wish - I can attach a file with my oryginal jar - but it would be a realy big file ;-)

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       



More information about the hibernate-issues mailing list