goool
goool

Reputation: 61

Can't initialize a transient member?

In grails 2.0.4, I hava a domain class like this:

class Foo {

    String pres
    String temp

    static transients = ['temp']

    def beforeInsert = {
        println "pres: ${pres}"
        println "temp: ${temp}"
    }
}

In BootStrap.groovy:

def f1 = new Foo(pres: "p1", temp: "t1")
f1.save()

def f2 = new Foo(pres: "p2")
f2.temp = "t2"
f2.save()

Then grails run-app, I got:

pres: p1
temp: null
pres: p2
temp: t2

What's the difference between f1 and f2, can't initialize a transient member?

Upvotes: 6

Views: 514

Answers (2)

Ian Roberts
Ian Roberts

Reputation: 122364

The bindable constraint allows you to override the default behaviour. It would typically be used to disable data binding for a property that would normally be bindable by default, but I believe you can use it the other way too.

Upvotes: 1

chrislatimer
chrislatimer

Reputation: 3560

I ran into this same thing after upgrading to Grails 2. See these two JIRA entries if you want more info:

http://jira.grails.org/browse/GRAILS-8972

http://jira.grails.org/browse/GRAILS-9098

But, ultimately, I've had to resort to the same work around that you did in your example.

Upvotes: 0

Related Questions