[hibernate-issues] [Hibernate-JIRA] Issue Comment Edited: (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 ...

Lukasz Antoniak (JIRA) noreply at atlassian.com
Tue Oct 18 09:48:19 EDT 2011


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

Lukasz Antoniak edited comment on HHH-3843 at 10/18/11 8:47 AM:
----------------------------------------------------------------

Steffen,

your sample project helped me in reproducing this issue. Thanks :). Error occurs if relation is encapsulated by the superclass. Without inheritance everything should work fine. Currently I have fixed {{NonUniqueObjectException}} but I run into another issue. Hibernate does not fire any DML operation on {{Person}} entity when I add {{Role}} to it. So the operation of adding a role to the person can be only seen while reading {{Role}}'s or {{RightsSubject}}'s history. I will try to fix this as soon as possible.

See the following code fragment:
{code}
// Revision 1
em.getTransaction().begin();
adam = em.find(Person.class, adam.getId());
admin = em.find(Role.class, admin.getId());
admin.getMembers().add(adam);
em.getTransaction().commit();
{code}
The following statements are true:
1. {{getAuditReader().getRevisions(Person.class, adam.getId())}} - returns no results.
2. {{getAuditReader().getRevisions(RightsSubject.class, adam.getId())}} - returns {1}.

I don't know if this is still the same issue and whether you can classify it as a bug. Adam, can you comment?

Regards,
Lukasz Antoniak

P.S. I am referring to mapping defined in envers-many2many_ticket3843.zip.

      was (Author: lukasz.antoniak):
    Steffen,

your sample project helped me in reproducing this issue. Thanks :). Error occurs if relation is encapsulated by the superclass. Without inheritance everything should work fine. Currently I have fixed {{NonUniqueObjectException}} but I run into another issue. Hibernate does not fire any DML operation on {{Person}} entity when I add {{Role}} to it. So the operation of adding a role to the person can be only seen while reading {{Role}}'s or {{RightsSubject}}'s history. I will try to fix this as soon as possible.

See the following code fragment:
{code}
// Revision 1
em.getTransaction().begin();
adam = em.find(Person.class, adam.getId());
admin = em.find(Role.class, admin.getId());
admin.getMembers().add(adam);
em.getTransaction().commit();
{code}
The following statements are true:
1. {{getAuditReader().getRevisions(Person.class, adam.getId())}} - returns no results.
2. {{getAuditReader().getRevisions(RightsSubject.class, adam.getId())}} - returns {1}.

I don't know if this is still the same issue and whether you can classify it as a bug. Adam, can you comment?

Regards,
Lukasz Antoniak
  
> @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
>            Assignee: Lukasz Antoniak
>         Attachments: enverse.7z, enverse.zip, envers-many2many_ticket3843.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.
For more information on JIRA, see: http://www.atlassian.com/software/jira

       



More information about the hibernate-issues mailing list