Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Cannot Reproduce
-
Affects Version/s: 1.1
-
Fix Version/s: 1.2-M2
-
Component/s: None
-
Labels:None
-
Environment:Tested on both Windows XP and Mac OS X 10.5
Description
I have a controller which deletes a domain object. The domain object has a beforeDelete event. In that event I load another domain object and try to delete it but nothing happens. There is a beforeDelete event in the ProductLevel object but that's not called either.
This is my beforeDelete event:
def beforeDelete = {
def pl = ProductLevel.get(objectId)
log.debug "To delete: " + pl
if(pl)
}
-
Hide
- before-delete-bug-report-22072009.zip
- 22/Jul/09 3:45 AM
- 17 kB
- Graeme Rocher
-
- grails-app/conf/BootStrap.groovy 0.2 kB
- grails-app/conf/Config.groovy 3 kB
- grails-app/conf/DataSource.groovy 0.6 kB
- grails-app/conf/UrlMappings.groovy 0.2 kB
- grails-app/conf/spring/resources.groovy 0.0 kB
- grails-app/.../ProductController.groovy 0.1 kB
- grails-app/domain/Product.groovy 0.2 kB
- grails-app/domain/ProductLevel.groovy 0.0 kB
- grails-app/i18n/messages.properties 3 kB
- grails-app/i18n/messages_de.properties 3 kB
- grails-app/i18n/messages_es.properties 3 kB
- grails-app/i18n/messages_fr.properties 2 kB
- grails-app/i18n/messages_it.properties 2 kB
- grails-app/i18n/messages_ja.properties 2 kB
- grails-app/i18n/messages_nl.properties 3 kB
- grails-app/.../messages_pt_BR.properties 3 kB
- grails-app/.../messages_pt_PT.properties 3 kB
- grails-app/i18n/messages_ru.properties 4 kB
- grails-app/i18n/messages_th.properties 5 kB
- grails-app/.../messages_zh_CN.properties 2 kB
- grails-app/views/error.gsp 2 kB
- grails-app/views/index.gsp 0.9 kB
- grails-app/views/layouts/main.gsp 0.7 kB
- test/unit/ProductControllerTests.groovy 0.2 kB
- test/unit/ProductLevelTests.groovy 0.2 kB
- test/unit/ProductTests.groovy 0.2 kB
Activity
- All
- Comments
- Work Log
- History
- Activity
- Git Commits
With the attached project and going to http://localhost:8080/before-delete/product/index I cannot reproduce the problem against Git HEAD
Please attach a project that reproduces the problem
One note, when the beforeDelete event fires, it is fired by Hibernate too late in the flushing process so delete() calls won't take effect unless you flush the session again. You can work around this in Grails 1.2 (when its released) by doing your updates in a new session. So you code would be:
def beforeDelete() {
ProductLevel.withNewSession {
def pl = ProductLevel.get(objectId)
log.debug "To delete: " + pl
if(pl) { log.debug "Calling delete" pl.delete() }
}
}
Which will work just fine
I believe I see the same phenomenon. Here are the relevant pieces of a little sample project I wrote to smoke out the bug:
Domain classes:
=============
class Person {
String name;
static constraints = {
}
static hasMany = [
initiating: Relationship,
recipient: Relationship
];
static mappedBy = [
initiating: 'initiator',
recipient: 'recipient'
];
static mapping =
{ initiating cascade:'all, delete-orphan' recipient cascade:'all, delete-orphan' }}
class Relationship {
String name;
Person initiator;
Person recipient;
static belongsTo = [initiator:Person, recipient:Person]
def beforeInsert =
{ initiator.addToInitiating(this); recipient.addToRecipient(this); }def beforeDelete =
{ System.out.println("This is not happening"); // Never fires. initiator?.removeFromInitiating(this); recipient?.removeFromRecipient(this); }static constraints = {
}
}
Failing integration test:
==================
import grails.test.*
class PersonTestTests extends GrailsUnitTestCase {
Person a;
Person b;
RelationshipType rt;
Relationship r;
protected void setUp()
{ super.setUp(); rt = new RelationshipType(name: "rt"); a = new Person(name: "a"); a.save(flush:true); b = new Person(name: "b"); b.save(flush:true); r = new Relationship(initiator: a, recipient: b, name: "relationship"); r.save(flush:true); }protected void tearDown()
{ super.tearDown() // r.delete(flush:true); a.delete(flush:true); b.delete(flush:true); a= null; b= null; r= null; }void testSomething() {
}
}