• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate: Found two representations of same collection

 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • 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 ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • 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.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay. I might try some garlic and exorcism if that doesn't help.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also downgraded to 2.1.6 and the problem persists.
 
Denys Mitin
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic