Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Blocker
-
Resolution: Fixed
-
Affects Version/s: 1.1.1, 1.2-M4
-
Fix Version/s: 1.2-RC1
-
Component/s: None
-
Labels:None
Description
If you use noSelection on a select box to a select relationship id - eg just like scaffolding but with noSelection=['':'None'] - this works for creating objects but not editing. If you save an existing object after changing its relationship to None from previously having one, you get hibernate errors.
What is strange is that it appears that the id of the actual child end of the relationship is being changed by the binding, rather than the id of it in the parent side.
Eg in the integration test, after binding null to "author.id", the author object has a null id, instead of the book having a null author. This is particularly worrying.
Attachments
-
$i18n.getText("admin.common.words.hide")
- ScaffoldTest-bug-report-20052009.zip
- 20/May/09 10:23 AM
- 36 kB
- Marc Palmer
-
- grails-app/conf/BootStrap.groovy 0.1 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/.../AuthorController.groovy 0.1 kB
- grails-app/.../BookController.groovy 0.0 kB
- grails-app/domain/Author.groovy 0.1 kB
- grails-app/domain/Book.groovy 0.1 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/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/author/create.gsp 2 kB
- grails-app/views/author/edit.gsp 2 kB
- grails-app/views/author/list.gsp 2 kB
- grails-app/views/author/show.gsp 2 kB
- grails-app/views/book/create.gsp 2 kB
- grails-app/views/book/edit.gsp 3 kB
- grails-app/views/book/list.gsp 2 kB
- grails-app/views/book/show.gsp 2 kB
- grails-app/views/error.gsp 2 kB
- grails-app/views/index.gsp 0.9 kB
$i18n.getText("admin.common.words.show")- ScaffoldTest-bug-report-20052009.zip
- 20/May/09 10:23 AM
- 36 kB
- Marc Palmer
Activity
- All
- Comments
- Work Log
- History
- Activity
- Git Commits
Is fix-for 1.1.2 still vaild? Should go into 1.2M2 asap really shouldn't it?
I don't think this bug was fixed in 1.2M2. At least for proxies, the problem remained.
There was a bug in the previous version of HibernatePluginSupport.enhanceProxy (also in 1.2-M2). It never set a proxy to null.
There was also another bug in the code (look at the code below: tries to set 'value' instead of 'val').
Previous code (1.2M2):
http://github.com/grails/grails/blob/v1.2M2/grails/src/java/org/codehaus/groovy/grails/plugins/orm/hibernate/HibernatePluginSupport.groovy
proxy.metaClass {
propertyMissing { String name, val ->
if(delegate instanceof HibernateProxy) {
def obj = GrailsHibernateUtil.unwrapProxy(delegate)
if(val != null) {
obj?."$name" = value
}
return obj."$name"
}
else {
throw new MissingPropertyException(name, delegate.class)
}
}
This has been fixed in the master branch:
http://github.com/grails/grails/blob/master/grails/src/java/org/codehaus/groovy/grails/plugins/orm/hibernate/HibernatePluginSupport.groovy
// getter mc.propertyMissing = { String name -> if(delegate instanceof HibernateProxy) { return GrailsHibernateUtil.unwrapProxy(delegate)."$name" } else { throw new MissingPropertyException(name, delegate.class) } } // setter mc.propertyMissing = { String name, val -> if(delegate instanceof HibernateProxy) { GrailsHibernateUtil.unwrapProxy(delegate)."$name" = val } else { throw new MissingPropertyException(name, delegate.class) } }
I've also added unit tests to LazyProxiedAssociationsWithInheritanceTests.testSettersOnProxiedObjects .
http://github.com/grails/grails/blob/master/grails/src/test/org/codehaus/groovy/grails/orm/hibernate/LazyProxiedAssociationsWithInheritanceTests.groovy
proxy.metaClass {
propertyMissing { String name, val ->
if(delegate instanceof HibernateProxy) {
def obj = GrailsHibernateUtil.unwrapProxy(delegate)
if(val != null) {
obj?."$name" = value
}
return obj."$name"
}
else {
throw new MissingPropertyException(name, delegate.class)
}
}
// getter mc.propertyMissing = { String name -> if(delegate instanceof HibernateProxy) { return GrailsHibernateUtil.unwrapProxy(delegate)."$name" } else { throw new MissingPropertyException(name, delegate.class) } } // setter mc.propertyMissing = { String name, val -> if(delegate instanceof HibernateProxy) { GrailsHibernateUtil.unwrapProxy(delegate)."$name" = val } else { throw new MissingPropertyException(name, delegate.class) } }
In the latest 1.2 SNAPSHOT, the "null-binding" functional test fails because an empty Author instance is being created when the UI passes "author.id=" to the server. I'm not sure what's supposed to be happening because the GrailsParameterMap instance contains an {{author: [id: "null"]}} entry as well as an "author.id":"null" one. I don't know whether both are required, but it's certainly confusing.
The problem seems to stem from "null" being a String, rather than a real null value.
This regression is because of Spring 3's new null path binding support. Spring 3 is autocreating the instance under the covers
Caused by http://jira.springframework.org/browse/SPR-6430
Will be fixed when we upgrade to Spring 3 final and call setAutoGrowNestedPaths(false)
fixed by upgrade to Spring 3 RC3.
Git SHA a3f53beba3d667643a31acbc4b4ea14333e0f21d
Doesn't work for creating a relationship either. With creating I get