Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Hibernate: Found two representations of same collection

 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I'm getting a HibernateException saying "Found two representations of same collection: domain.Email.recipients" when updating a class that's holding a java.util.Set of java.lang.Strings. Doing a Session#save() on the same object works perfect. It's just the Session#update() that's making trouble here.

I tried searching the Hibernate forum and found a couple of old threads that discussed the same problem but there were no solutions offered. (I also tried reading the auto-translated Russian Hibernate forum but no luck there either)

Here's all the relevant pieces:

I'm using Hibernate version 2.1.7c against PostgreSQL 8.0.0-rc4 (Win32).

The mapping document:


Database tables:


The Java class being mapped:


The piece of code doing the failing update:


The stack trace of the exception that gets thrown:


The generated SQL:


And, finally, the debug level Hibernate log excerpt:


Big thanks for reading this far!
[ January 16, 2005: Message edited by: Lasse Koskela ]
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Were there *any* replies to the threads you found? I don't have the slightest idea what that error message even means...

My first idea would be to take a look at the source code where the exception is thrown. Perhaps I will find the time to do that tomorrow at work...
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There were replies alright but none that helped, unfortunately.
I'll also dig inside Hibernate tomorrow. Remind me to report back my findings if you don't hear from me...
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Should I perhaps specify a primary key for the email_recipient table?
E.g.

It just occurred to me that Hibernate might check for this since the semantics of a Set not containing duplicate entries would effectively translate to such a primary key in the database. Does it (check such things)?

I'm not in a place where I could try it out right now so I'll have to report back later after trying that... In the meanwhile, I'd appreciate a confirmation one way or the other, of course.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Should I perhaps specify a primary key for the email_recipient table


Absolutely. I've not seen the error you are getting before, but I'd suspect its because you have a table with no PK. The Hibernate developers are very strict about a relational value requiring a PK, because they (quite correctly) state that without one its not a relational value. Given their assumption, I would imagine that somewhere in their code your model is causing identity problems, hence the error.
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code is a little bit, well, obscure:



I didn't find any comment in an addCollection method, though. :roll: Well, what do you expect from a 3000 line class...

It's doubly confusing because getCollectionEntry just looks it up in a Map and null means that *it wasn't found at all*, as far as I can tell. I don't have the slightest idea what that has to do with *more* than one representation...

Lasse, all I can advice you to do is running the code through your preferred debugger, crossing fingers and execrating the hibernate developers...
[ January 17, 2005: Message edited by: Ilja Preuss ]
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay. I might try some garlic and exorcism if that doesn't help.
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Paul Sturrock:
Absolutely. I've not seen the error you are getting before, but I'd suspect its because you have a table with no PK. The Hibernate developers are very strict about a relational value requiring a PK, because they (quite correctly) state that without one its not a relational value. Given their assumption, I would imagine that somewhere in their code your model is causing identity problems, hence the error.


Nope. I added a primary key (email_id, email_recipient) to the table but that didn't help. I also let Hibernate auto-create the table and it didn't work with that either (and it didn't create a primary key for that table, by the way).
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also downgraded to 2.1.6 and the problem persists.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ilja Preuss wrote:I didn't find any comment in an addCollection method, though.


You probably looked on wrong version of source code or wrong variant of method.
For me it looks like there is enough information
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Denys, welcome to CodeRanch!

The thread is 9 year old so it's possible that the version which Ilja looked at didn't have those comments at that time and the newer version probably has it.
 
reply
    Bookmark Topic Watch Topic
  • New Topic