Is there any difference between 'static transients' and 'transient Type aField' declaration for GORM?
Asked Answered
W

1

12

Let us consider two Grails domain example classes.

1st class:

class Person {

    String name
    Integer counter = 0

    static transients = ['counter']
}

2nd class:

class Vehicle {

    String name
    transient Integer counter = 0
}

Will there be any difference in GORM persistence or domain class behaviour for the Integer counter field between classes Person and Vehicle?

EDIT: I know that Person class is the good way to do it as referenced by Grails docs. However I would prefer the Vehicle class way as it seems to be more obvious and easier not to overlook when reading a code.

Wattle answered 17/9, 2012 at 15:12 Comment(0)
M
16

The two mechanisms define different kinds of "transience". static transients defines bean properties that should not be mapped to the database by Hibernate, whereas the transient keyword denotes a field that should not be saved by the Java object serialization mechanism (e.g. when using webflow). They both have their uses in different situations.

Mckeehan answered 17/9, 2012 at 17:49 Comment(1)
Yup, this is true. I was kind of aware about that, but when a property is put in static transients list, then it's not serialized either (for example when 'as XML' casting used). So it was behaviour similar to transient keyword. I have also checked now, that transient Integer counter is exported to the DB schema anyway, so indeed those two have nothing common between. Anyway, your answer is fair enough, thanks!Wattle

© 2022 - 2024 — McMap. All rights reserved.