Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Won't Fix
-
Affects Version/s: 1.1.1, 1.2.2
-
Component/s: Persistence
-
Labels:None
-
Environment:CentOS 5, MySQL 5 (InnoDB), HSQLDB
-
Testcase included:yes
Description
A many-to-many relationship between two domain classes where one or both of the domain class holds the relationship in a list appears to save incorrectly in the join table.
If one side of the many-to-many relation has a List instead of a Set, then a duplicate key exception is generated during save:
'org.hibernate.util.JDBCExceptionReporter - Duplicate entry '5-3' for key 1'
If both sides of the many-to-many relation have a List instead of a Set, then there is no duplicate key exception. However, the join table has two entries added, with the idx row null for one of the lists:
--------------------------------+
| game_id | ref_id | refs_idx | games_idx |
--------------------------------+
| 1 | 3 | NULL | 0 |
| 1 | 3 | 0 | NULL |
The save appears to succeed but loading the collection later results in a null index exception: 'org.hibernate.HibernateException: null index column for collection: Ref.games'
class Ref { static hasMany = [whistles:Whistle, games:Game] String name List whistles List games }class Whistle { static hasMany = [refs:Ref] static belongsTo = Ref String name }class Whistle { static hasMany = [refs:Ref] static belongsTo = Ref String name }void testSaveManyToManyWithOneList() { def ref = new Ref(name: 'John') def whistle = new Whistle(name: 'Whistle') ref.addToWhistles(whistle) ref.save(flush:true) // duplicate key exception } void testSaveManyToManyWithTwoLists() { def ref = new Ref(name: 'John') def game = new Game(name: 'Match 2010') ref.addToGames(game) ref.save(flush:true) def refId = ref.id ref.discard() ref = Ref.get(refId) ref.games // will throw a null index column exception if many-to-many save was invalid }