Quantcast

Map constructors with transients in Grails 2.1

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Map constructors with transients in Grails 2.1

dalew75
I'm in the process of upgrading a large application from 1.3.7 to 2.1.   An issue I just ran into is this:     If you use a Map constructor on a domain object, it will not populate the transient fields anymore.

eg:
MyDomainObject o = new MyDomainObject (
                        var1: 'test',
                        var2: 'test',
                        var3: 'test',
                        var4: 'test',
                        transientVar1: 'test',
                )

In this case , the tranient var will not be populated.  You need to do a regular assignment

For many reasons, we are actually moving away from using Map constructors anyways (IDE support etc), but that's in process.  

Figured I'd put this out there in case anyone else gets burned.  I assume this is planned to some degree, and is probably because the Map constructor is trying to be more efficient about only dealing with 'known' fields? (in this case persisted only)??
Dale Wiggins
Architect/Developer
StudentUniverse
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Map constructors with transients in Grails 2.1

burtbeckwith
See the section "Grails 2.0.2 Data Binding Improvements" in http://blog.springsource.org/2012/03/28/secure-data-binding-with-grails/

Burt

dalew75 wrote
I'm in the process of upgrading a large application from 1.3.7 to 2.1.   An issue I just ran into is this:     If you use a Map constructor on a domain object, it will not populate the transient fields anymore.

eg:
MyDomainObject o = new MyDomainObject (
                        var1: 'test',
                        var2: 'test',
                        var3: 'test',
                        var4: 'test',
                        transientVar1: 'test',
                )

In this case , the tranient var will not be populated.  You need to do a regular assignment

For many reasons, we are actually moving away from using Map constructors anyways (IDE support etc), but that's in process.  

Figured I'd put this out there in case anyone else gets burned.  I assume this is planned to some degree, and is probably because the Map constructor is trying to be more efficient about only dealing with 'known' fields? (in this case persisted only)??
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Map constructors with transients in Grails 2.1

dalew75
Thanks Burt!
Dale Wiggins
Architect/Developer
StudentUniverse
Loading...