|
I have a class class Product{ static hasMany = [competitorProducts : Product]
static mapping = { competitorProducts joinTable:[name:'product_competitor_products', key:'product_id', column:'competitor_product_id'] } } Now, lets say I add three competitor products to a product x using x.addToCompetitorProducts, It will insert three records into the product_competitor_products table Next time when user select different competitor products from UI for product x I do, x.competitorProduct.clear() and then add all the newly selected competitor product using x.addToCompetitorProducts. But the table will some time remove the old records and some time not, some time the old three records may not be cleared. I dont know why, but it creates duplicate records of same competitor products for product x in the table. even though I do x.competitorProduct.clear() before adding
any new records to the list, how can it create the duplicate records! Did i hit some bug ? or may be I am doing some thing wrong ? Sudhir |
|
This is surely a bug, and it happens when the same competitor products are added again, after doing product.competitorProducts.clear() Sudhir From: "[hidden email]" <[hidden email]> To: Grails-user <[hidden email]> Sent: Friday, 16 September 2011 11:21 PM Subject: [grails-user] hasMany JoinTable issue - does not delete records from the join table I have a class class Product{ static hasMany = [competitorProducts : Product]
static mapping = { competitorProducts joinTable:[name:'product_competitor_products', key:'product_id', column:'competitor_product_id'] } } Now, lets say I add three competitor products to a product x using x.addToCompetitorProducts, It will insert three records into the product_competitor_products table Next time when user select different competitor products from UI for product x I do, x.competitorProduct.clear() and then add all the newly selected competitor product using x.addToCompetitorProducts. But the table will some time remove the old records and some time not, some time the old three records may not be cleared. I dont know why, but it creates duplicate records of same competitor products for product x in the table. even though I do x.competitorProduct.clear() before adding
any new records to the list, how can it create the duplicate records! Did i hit some bug ? or may be I am doing some thing wrong ? Sudhir |
|
This looks a very serious issue, can any one please try to reproduce it and post results here? Sudhir From: "[hidden email]" <[hidden email]> To: "[hidden email]" <[hidden email]> Sent: Saturday, 17 September 2011 1:41 PM Subject: Re: [grails-user] hasMany JoinTable issue - does not delete records from the join table This is surely a bug, and it happens when the same competitor products are added again, after doing product.competitorProducts.clear() Sudhir From: "[hidden email]" <[hidden email]> To: Grails-user <[hidden email]> Sent: Friday, 16 September 2011 11:21 PM Subject: [grails-user] hasMany JoinTable issue - does not delete records from the join table I have a class class Product{ static hasMany = [competitorProducts : Product]
static mapping = { competitorProducts joinTable:[name:'product_competitor_products', key:'product_id', column:'competitor_product_id'] } } Now, lets say I add three competitor products to a product x using x.addToCompetitorProducts, It will insert three records into the product_competitor_products table Next time when user select different competitor products from UI for product x I do, x.competitorProduct.clear() and then add all the newly selected competitor product using x.addToCompetitorProducts. But the table will some time remove the old records and some time not, some time the old three records may not be cleared. I dont know why, but it creates duplicate records of same competitor products for product x in the table. even though I
do x.competitorProduct.clear() before adding
any new records to the list, how can it create the duplicate records! Did i hit some bug ? or may be I am doing some thing wrong ? Sudhir |
|
I think you should have a look at this .. I think it describes your situation exactly .. From: "[hidden email]" <[hidden email]> To: "[hidden email]" <[hidden email]> Sent: Saturday, 17 September 2011, 9:33 Subject: Re: [grails-user] hasMany JoinTable issue - does not delete records from the join table This looks a very serious issue, can any one please try to reproduce it and post results here? Sudhir From: "[hidden email]" <[hidden email]> To: "[hidden email]" <[hidden email]> Sent: Saturday, 17 September 2011 1:41 PM Subject: Re: [grails-user] hasMany JoinTable issue - does not delete records from the join table This is surely a bug, and it happens when the same competitor products are added
again, after doing product.competitorProducts.clear() Sudhir From: "[hidden email]" <[hidden email]> To: Grails-user <[hidden email]> Sent: Friday, 16 September 2011 11:21 PM Subject: [grails-user] hasMany JoinTable issue - does not delete records from the join table I have a class class Product{ static hasMany = [competitorProducts : Product]
static mapping = { competitorProducts joinTable:[name:'product_competitor_products', key:'product_id', column:'competitor_product_id'] } } Now, lets say I add three competitor products to a product x using x.addToCompetitorProducts, It will insert three records into the product_competitor_products table Next time when user select different competitor products from UI for product x I do, x.competitorProduct.clear() and then add all the newly selected competitor product using x.addToCompetitorProducts. But the table will some time remove the old records and some time not, some time the old three records may not be cleared. I dont know why, but it creates duplicate records of same competitor products for product x in the table. even though I
do x.competitorProduct.clear() before adding
any new records to the list, how can it create the duplicate records! Did i hit some bug ? or may be I am doing some thing wrong ? Sudhir |
|
I think it does not describe the situation that I am facing, 1. First of all, it talks about clear() not working for the bidirectional relationships, however mine is unidirectional. 2. It says clear() does not work when using foreign key, but works for joinTable, however in my case, it is not working for even when I am using the joinTable. 3. And it does not explain the duplicate records which are inserted in the Join table. And why this duplicate records aren't causing exception even when the relationship is actually a Set, which needs unique records. 4. Why the Set contains just unique records even though there are duplicate records in the table. So
it looks surely there's some thing wrong. Thanks Sudhir From: Rob Morning <[hidden email]> To: "[hidden email]" <[hidden email]> Sent: Saturday, 17 September 2011 4:11 PM Subject: Re: [grails-user] hasMany JoinTable issue - does not delete records from the join table I think you should have a look at this .. I think it describes your situation exactly .. From: "[hidden email]" <[hidden email]> To: "[hidden email]" <[hidden email]> Sent: Saturday, 17 September 2011, 9:33 Subject: Re: [grails-user] hasMany JoinTable issue - does not delete records from the join table This looks a very serious issue, can any one please try to reproduce it and post results here? Sudhir From: "[hidden email]" <[hidden email]> To: "[hidden email]" <[hidden email]> Sent: Saturday, 17 September 2011 1:41 PM Subject: Re: [grails-user] hasMany JoinTable issue - does not delete records from the join table This is surely a bug, and it happens when the same competitor products are added
again, after doing product.competitorProducts.clear() Sudhir From: "[hidden email]" <[hidden email]> To: Grails-user <[hidden email]> Sent: Friday, 16 September 2011 11:21 PM Subject: [grails-user] hasMany JoinTable issue - does not delete records from the join table I have a class class Product{ static hasMany = [competitorProducts : Product]
static mapping = { competitorProducts joinTable:[name:'product_competitor_products', key:'product_id', column:'competitor_product_id'] } } Now, lets say I add three competitor products to a product x using x.addToCompetitorProducts, It will insert three records into the product_competitor_products table Next time when user select different competitor products from UI for product x I do, x.competitorProduct.clear() and then add all the newly selected competitor product using x.addToCompetitorProducts. But the table will some time remove the old records and some time not, some time the old three records may not be cleared. I dont know why, but it creates duplicate records of same competitor products for product x in the table. even though I
do x.competitorProduct.clear() before adding
any new records to the list, how can it create the duplicate records! Did i hit some bug ? or may be I am doing some thing wrong ? Sudhir |
|
To make it more worse, Using removeFromX too does not work in my case, if I do removeFromX and then re-add the same object which was just removed, still it will create duplicate records in the table. However If I add different object after doing removeFromX, it will delete the old record from table and insert new. IF there are duplicate records Y and I do, removeFromX(y) and then instead of again adding Y, add some other object, all the duplicate records of Y will be deleted from join table. It is weird. Thanks Sudhir From: "[hidden email]" <[hidden email]> To: "[hidden email]" <[hidden email]> Sent: Saturday, 17 September 2011 7:56 PM Subject: Re: [grails-user] hasMany JoinTable issue - does not delete records from the join table I think it does not describe the situation that I am facing, 1. First of all, it talks about clear() not working for the bidirectional relationships, however mine is unidirectional. 2. It says clear() does not work when using foreign key, but works for joinTable, however in my case, it is not working for even when I am using the
joinTable. 3. And it does not explain the duplicate records which are inserted in the Join table. And why this duplicate records aren't causing exception even when the relationship is actually a Set, which needs unique records. 4. Why the Set contains just unique records even though there are duplicate records in the table. So
it looks surely there's some thing wrong. Thanks Sudhir From: Rob Morning <[hidden email]> To: "[hidden email]" <[hidden email]> Sent: Saturday, 17 September 2011 4:11 PM Subject: Re: [grails-user] hasMany JoinTable issue - does not delete records from the join table I think you should have a look at this .. I think it describes your situation exactly .. From: "[hidden email]" <[hidden email]> To: "[hidden email]" <[hidden email]> Sent: Saturday, 17 September 2011, 9:33 Subject: Re: [grails-user] hasMany JoinTable issue - does not delete records from the join table This looks a very serious issue, can any one please try to reproduce it and post results here? Sudhir From: "[hidden email]" <[hidden email]> To: "[hidden email]" <[hidden email]> Sent: Saturday, 17 September 2011 1:41 PM Subject: Re: [grails-user] hasMany JoinTable issue - does not delete records from the join table This is surely a bug, and it happens when the same competitor products are added
again, after doing product.competitorProducts.clear() Sudhir From: "[hidden email]" <[hidden email]> To: Grails-user <[hidden email]> Sent: Friday, 16 September 2011 11:21 PM Subject: [grails-user] hasMany JoinTable issue - does not delete records from the join table I have a class class Product{ static hasMany = [competitorProducts : Product]
static mapping = { competitorProducts joinTable:[name:'product_competitor_products', key:'product_id', column:'competitor_product_id'] } } Now, lets say I add three competitor products to a product x using x.addToCompetitorProducts, It will insert three records into the product_competitor_products table Next time when user select different competitor products from UI for product x I do, x.competitorProduct.clear() and then add all the newly selected competitor product using x.addToCompetitorProducts. But the table will some time remove the old records and some time not, some time the old three records may not be cleared. I dont know why, but it creates duplicate records of same competitor products for product x in the table. even though I
do x.competitorProduct.clear() before adding
any new records to the list, how can it create the duplicate records! Did i hit some bug ? or may be I am doing some thing wrong ? Sudhir |
|
Actually it specifically mentions unidirectional ... "As with other relationships, mastering collections means mastering their
cascading behaviour. The first thing to note is that saves are always
cascaded from the parent to its children, even if there is no belongsTo specified. " From: "[hidden email]" <[hidden email]> To: "[hidden email]" <[hidden email]> Sent: Saturday, 17 September 2011, 15:55 Subject: Re: [grails-user] hasMany JoinTable issue - does not delete records from the join table To make it more worse, Using removeFromX too does not work in my case, if I do removeFromX and then re-add the same object which was just removed, still it will create duplicate records in the table. However If I add different object after doing removeFromX, it will delete the old record from table and insert new. IF there are duplicate records Y and I do, removeFromX(y) and then instead of again adding Y, add some other object, all the duplicate records of Y will be deleted from join table. It
is weird. Thanks Sudhir From: "[hidden email]" <[hidden email]> To: "[hidden email]" <[hidden email]> Sent: Saturday, 17 September 2011 7:56 PM Subject: Re: [grails-user] hasMany JoinTable issue - does not delete records from the join table I think it does not describe the situation that I am facing, 1. First of all, it talks about clear() not working for the bidirectional relationships, however mine is unidirectional. 2. It says clear() does not work when using foreign key, but works for joinTable, however in my case, it is not working for even when I am using the
joinTable. 3. And it does not explain the duplicate records which are inserted in the Join table. And why this duplicate records aren't causing exception even when the relationship is actually a Set, which needs unique records. 4. Why the Set contains just unique records even though there are duplicate records in the table. So
it looks surely there's some thing wrong. Thanks Sudhir From: Rob Morning <[hidden email]> To: "[hidden email]" <[hidden email]> Sent: Saturday, 17 September 2011 4:11 PM Subject: Re: [grails-user] hasMany JoinTable issue - does not delete records from the join table I think you should have a look at this .. I think it describes your situation exactly .. From: "[hidden email]" <[hidden email]> To: "[hidden email]" <[hidden email]> Sent: Saturday, 17 September 2011, 9:33 Subject: Re: [grails-user] hasMany JoinTable issue - does not delete records from the join table This looks a very serious issue, can any one please try to reproduce it and post results here? Sudhir From: "[hidden email]" <[hidden email]> To: "[hidden email]" <[hidden email]> Sent: Saturday, 17 September 2011 1:41 PM Subject: Re: [grails-user] hasMany JoinTable issue - does not delete records from the join table This is surely a bug, and it happens when the same competitor products are added
again, after doing product.competitorProducts.clear() Sudhir From: "[hidden email]" <[hidden email]> To: Grails-user <[hidden email]> Sent: Friday, 16 September 2011 11:21 PM Subject: [grails-user] hasMany JoinTable issue - does not delete records from the join table I have a class class Product{ static hasMany = [competitorProducts : Product]
static mapping = { competitorProducts joinTable:[name:'product_competitor_products', key:'product_id', column:'competitor_product_id'] } } Now, lets say I add three competitor products to a product x using x.addToCompetitorProducts, It will insert three records into the product_competitor_products table Next time when user select different competitor products from UI for product x I do, x.competitorProduct.clear() and then add all the newly selected competitor product using x.addToCompetitorProducts. But the table will some time remove the old records and some time not, some time the old three records may not be cleared. I dont know why, but it creates duplicate records of same competitor products for product x in the table. even though I
do x.competitorProduct.clear() before adding
any new records to the list, how can it create the duplicate records! Did i hit some bug ? or may be I am doing some thing wrong ? Sudhir |
|
This raises an interesting question: why doesn't the clear() method work on a bidirectional relationship? I'm not 100% sure, but I believe it's because the books retain a back reference to the author. To understand why that would affect the behaviour of clear(), you must first realise that GORM maps unidirectional and bidirectional one-to-many
relationships to database tables differently. For unidirectional relationships, GORM creates a join table by default, so when you clear the collection of books, the records are simply removed from that join table. Expecting some grails dev to clarify. Sudhir From: Rob Morning <[hidden email]> To: "[hidden email]" <[hidden email]> Sent: Saturday, 17 September 2011 9:47 PM Subject: Re: [grails-user] hasMany JoinTable issue - does not delete records from the join table Actually it specifically mentions unidirectional ... "As with other relationships, mastering collections means mastering their
cascading behaviour. The first thing to note is that saves are always
cascaded from the parent to its children, even if there is no belongsTo specified. " From: "[hidden email]" <[hidden email]> To: "[hidden email]" <[hidden email]> Sent: Saturday, 17 September 2011, 15:55 Subject: Re: [grails-user] hasMany JoinTable issue - does not delete records from the join table To make it more worse, Using removeFromX too does not work in my case, if I do removeFromX and then re-add the same object which was just removed, still it will create duplicate records in the table. However If I add different object after doing removeFromX, it will delete the old record from table and insert new. IF there are duplicate records Y and I do, removeFromX(y) and then instead of again adding Y, add some other object, all the duplicate records of Y will be deleted from join table. It
is weird. Thanks Sudhir From: "[hidden email]" <[hidden email]> To: "[hidden email]" <[hidden email]> Sent: Saturday, 17 September 2011 7:56 PM Subject: Re: [grails-user] hasMany JoinTable issue - does not delete records from the join table I think it does not describe the situation that I am facing, 1. First of all, it talks about clear() not working for the bidirectional relationships, however mine is unidirectional. 2. It says clear() does not work when using foreign key, but works for joinTable, however in my case, it is not working for even when I am using the
joinTable. 3. And it does not explain the duplicate records which are inserted in the Join table. And why this duplicate records aren't causing exception even when the relationship is actually a Set, which needs unique records. 4. Why the Set contains just unique records even though there are duplicate records in the table. So
it looks surely there's some thing wrong. Thanks Sudhir From: Rob Morning <[hidden email]> To: "[hidden email]" <[hidden email]> Sent: Saturday, 17 September 2011 4:11 PM Subject: Re: [grails-user] hasMany JoinTable issue - does not delete records from the join table I think you should have a look at this .. I think it describes your situation exactly .. From: "[hidden email]" <[hidden email]> To: "[hidden email]" <[hidden email]> Sent: Saturday, 17 September 2011, 9:33 Subject: Re: [grails-user] hasMany JoinTable issue - does not delete records from the join table This looks a very serious issue, can any one please try to reproduce it and post results here? Sudhir From: "[hidden email]" <[hidden email]> To: "[hidden email]" <[hidden email]> Sent: Saturday, 17 September 2011 1:41 PM Subject: Re: [grails-user] hasMany JoinTable issue - does not delete records from the join table This is surely a bug, and it happens when the same competitor products are added
again, after doing product.competitorProducts.clear() Sudhir From: "[hidden email]" <[hidden email]> To: Grails-user <[hidden email]> Sent: Friday, 16 September 2011 11:21 PM Subject: [grails-user] hasMany JoinTable issue - does not delete records from the join table I have a class class Product{ static hasMany = [competitorProducts : Product]
static mapping = { competitorProducts joinTable:[name:'product_competitor_products', key:'product_id', column:'competitor_product_id'] } } Now, lets say I add three competitor products to a product x using x.addToCompetitorProducts, It will insert three records into the product_competitor_products table Next time when user select different competitor products from UI for product x I do, x.competitorProduct.clear() and then add all the newly selected competitor product using x.addToCompetitorProducts. But the table will some time remove the old records and some time not, some time the old three records may not be cleared. I dont know why, but it creates duplicate records of same competitor products for product x in the table. even though I
do x.competitorProduct.clear() before adding
any new records to the list, how can it create the duplicate records! Did i hit some bug ? or may be I am doing some thing wrong ? Sudhir |
|
Can any core grails dev clarify the behavior in my case or confirm the bug ? Sudhir From: "[hidden email]" <[hidden email]> To: "[hidden email]" <[hidden email]> Sent: Saturday, 17 September 2011 10:31 PM Subject: Re: [grails-user] hasMany JoinTable issue - does not delete records from the join table This raises an interesting question: why doesn't the clear() method work on a bidirectional relationship? I'm not 100% sure, but I believe it's because the books retain a back reference to the author. To understand why that would affect the behaviour of clear(), you must first realise that GORM maps unidirectional and bidirectional one-to-many
relationships to database tables differently. For unidirectional relationships, GORM creates a join table by default, so when you clear the collection of books, the records are simply removed from that join table. Expecting some grails dev to clarify. Sudhir From: Rob Morning <[hidden email]> To: "[hidden email]" <[hidden email]> Sent: Saturday, 17 September 2011 9:47 PM Subject: Re: [grails-user] hasMany JoinTable issue - does not delete records from the join table Actually it specifically mentions unidirectional ... "As with other relationships, mastering collections means mastering their
cascading behaviour. The first thing to note is that saves are always
cascaded from the parent to its children, even if there is no belongsTo specified. " From: "[hidden email]" <[hidden email]> To: "[hidden email]" <[hidden email]> Sent: Saturday, 17 September 2011, 15:55 Subject: Re: [grails-user] hasMany JoinTable issue - does not delete records from the join table To make it more worse, Using removeFromX too does not work in my case, if I do removeFromX and then re-add the same object which was just removed, still it will create duplicate records in the table. However If I add different object after doing removeFromX, it will delete the old record from table and insert new. IF there are duplicate records Y and I do, removeFromX(y) and then instead of again adding Y, add some other object, all the duplicate records of Y will be deleted from join table. It
is weird. Thanks Sudhir From: "[hidden email]" <[hidden email]> To: "[hidden email]" <[hidden email]> Sent: Saturday, 17 September 2011 7:56 PM Subject: Re: [grails-user] hasMany JoinTable issue - does not delete records from the join table I think it does not describe the situation that I am facing, 1. First of all, it talks about clear() not working for the bidirectional relationships, however mine is unidirectional. 2. It says clear() does not work when using foreign key, but works for joinTable, however in my case, it is not working for even when I am using the
joinTable. 3. And it does not explain the duplicate records which are inserted in the Join table. And why this duplicate records aren't causing exception even when the relationship is actually a Set, which needs unique records. 4. Why the Set contains just unique records even though there are duplicate records in the table. So
it looks surely there's some thing wrong. Thanks Sudhir From: Rob Morning <[hidden email]> To: "[hidden email]" <[hidden email]> Sent: Saturday, 17 September 2011 4:11 PM Subject: Re: [grails-user] hasMany JoinTable issue - does not delete records from the join table I think you should have a look at this .. I think it describes your situation exactly .. From: "[hidden email]" <[hidden email]> To: "[hidden email]" <[hidden email]> Sent: Saturday, 17 September 2011, 9:33 Subject: Re: [grails-user] hasMany JoinTable issue - does not delete records from the join table This looks a very serious issue, can any one please try to reproduce it and post results here? Sudhir From: "[hidden email]" <[hidden email]> To: "[hidden email]" <[hidden email]> Sent: Saturday, 17 September 2011 1:41 PM Subject: Re: [grails-user] hasMany JoinTable issue - does not delete records from the join table This is surely a bug, and it happens when the same competitor products are added
again, after doing product.competitorProducts.clear() Sudhir From: "[hidden email]" <[hidden email]> To: Grails-user <[hidden email]> Sent: Friday, 16 September 2011 11:21 PM Subject: [grails-user] hasMany JoinTable issue - does not delete records from the join table I have a class class Product{ static hasMany = [competitorProducts : Product]
static mapping = { competitorProducts joinTable:[name:'product_competitor_products', key:'product_id', column:'competitor_product_id'] } } Now, lets say I add three competitor products to a product x using x.addToCompetitorProducts, It will insert three records into the product_competitor_products table Next time when user select different competitor products from UI for product x I do, x.competitorProduct.clear() and then add all the newly selected competitor product using x.addToCompetitorProducts. But the table will some time remove the old records and some time not, some time the old three records may not be cleared. I dont know why, but it creates duplicate records of same competitor products for product x in the table. even though I
do x.competitorProduct.clear() before adding
any new records to the list, how can it create the duplicate records! Did i hit some bug ? or may be I am doing some thing wrong ? Sudhir |
| Powered by Nabble | Edit this page |
